r/learnpython • • 6h ago

while loop behaves unexpectedly

3 Upvotes

Been at this for a while and can't seem to make sense of why a multi-conditioned while loop only triggers when one condition is met, but not the other, which generally happens sooner before the 2nd condition is met.

The results I get running the sample:import random
numList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
randNum = int(random.randint(1, 10))
numMatch = False
maxNum = 9
incCount = 0

while numMatch == False or incCount <= maxNum:
    if numList[incCount] == randNum:
        numMatch = True
    
    print(numList[incCount])
    incCount += 1
print('Random number: ' + str(randNum) + '\n')
print('numMatch: ' + str(numMatch))


Y:\Users\lailoken\Documents\Python>python sample.py
1
2
3
4
5
6
7
8
9
10
Random number: 3
numMatch: True

The second condition triggers but not the Boolean, and I'm stumped as to why.


r/learnpython • • 17h ago

Help me set up my environment for this project

0 Upvotes

I used to dabble around with Python from time to time...

However every time I come back to it I seem to hit this brick wall before I even get to write a line of code.

Long story short, I want to do the tutorial you find here:
https://www.youtube.com/watch?v=8OMghdHP-zs

I just wanna get to work instead of spending hours and hours grappling with things not installing properly, as it is yet again doing to me right now. So either help me fix the errors I am getting or show me the easy alternative.

I'd rather not use VSCode because it's Microsoft and it seems almost impossible to disable the AI "copilot" thing, from what I read online, so I'd rather not if that's the case.

I used to use Anaconda to set up environments using older versions of python and pygame, however, setting up an environment with python 3.14 it throws this at me when I activate it:

C:\Users\Mokpo>if exist "C:\Windows\System32\msmpi.dll" (

echo "You seem to have a system wide installation of MSMPI. "

echo "Due to the way DLL loading works on windows, system wide installation "

echo "will probably overshadow the conda installation. Uninstalling "

echo "the system wide installation and forced deleting C:\Windows\System32\msmpi*.dll"

echo "will help, but may break other software using the system wide installation.")

C:\Users\Mokpo>if defined MSMPI_BIN (set "MSMPI_BIN_CONDA_BACKUP=" )

C:\Users\Mokpo>if defined MSMPI_INC (set "MSMPI_INC_CONDA_BACKUP=" )

C:\Users\Mokpo>if defined MSMPI_LIB64 (set "MSMPI_LIB64_CONDA_BACKUP=" )

C:\Users\Mokpo>if defined MSMPI_LIB32 (set "MSMPI_LIB32_CONDA_BACKUP=" )

C:\Users\Mokpo>set MSMPI_BIN=\Library\bin

C:\Users\Mokpo>set MSMPI_INC=\Library\include

C:\Users\Mokpo>set MSMPI_LIB64=\Library\lib

C:\Users\Mokpo>set MSMPI_LIB32=""

Okay so it's recommending me to delete a file on which other things may depend system-wide, because Anaconda cannot get the environment to isolate itself from it and use the "proper" version instead? Will that not risk me breaking my OS in some horrible way?

Anyway. After typing "spyder" I get an error popup window titled: "analysecrash.exe - Application Error" saying "The application was unable to start correctly (0xc0000142). Click OK to close the application." This happens again once after I click okay.

However, Spyder does in fact launch, except it doesn't do anything. As in, I can make a folder into a project, theres a "temp.py" file open in the editor, I write print('hello world'); and click "run" but it doesnt do anything.

When I was trying this before, it did say something somewhere about the console not working because "the kernel" isnt loaded or whatever?

Anyway, this is extremely, extremely frustrating, especially as so many "beginners tutorials" seem hell-bent on skipping over any of this preliminary setup stuff like it's hot lava, while 99% of the actual beginners presumably die before they get to even try out much code, you know, like it's hot lava they cant skip over yet. I've written some programs in python before so I'm not even a beginner it's just this stuff is so obscure and it always manages to "snipe" me somehow whenever I try something new. So more generally, if there's a way to learn to deal with these kinds of problems, finding out more about how it works, etc... How do I become the person that answers these questions rather than asks them?


r/learnpython • • 18h ago

Candy Cane Coding Caper

4 Upvotes

For Advent I just launched Candy Cane Coding Caper, a coding adventure inspired by Advent of Code, for kids 8-12. Each day presents an interactive, structured lesson about a simple Python programming concept. I thought this community might like to take a look!

This is brand new and I would love any feedback or questions!

https://candy-cane.coding-caper.com


r/learnpython • • 22h ago

Where should I store user created modules?

5 Upvotes

Good morning,

I use conda environments with pandas for updating product information and data analysis.

I use Windows 11 and Fedora, but am more often using Windows.

I want to start creating and storing my own modules and packages for ease of use on my own machine for private use.

Is there a dedicated storage location for user created modules as there is for say Powershell 7?

I've asked chatgpt and searched google but a lot of the information is conflicting.

Are there dedicated locations and methods of retrieval depending on OS used?


r/learnpython • • 17h ago

Pandas scripts I copied together for our weekly reports keep breaking and nobody at work knows Python

0 Upvotes

I put together a few Python scripts that pull two CSV exports and merge them with pandas.

One of the exports renamed a column and the merge started throwing a KeyError. I still don't really get half of what the script does. Nobody here knows Python.

I want to know these scripts well enough to fix them myself. What helped you go from pasting code to understanding what your own code does?


r/learnpython • • 14h ago

Advent of Code 2026

14 Upvotes

Join the Advent of Code Challenge with Python!

Hey Pythonistas! 🐍

It's that exciting time of the year again! The Advent of Code has just started, and we're inviting everyone to join in the fun!

What is Advent of Code?

Advent of Code is an annual online event that runs from December 1st to December 12th (or til the 25th for older years). Each day, a new coding challenge is released—two puzzles that are part of a continuing story. It's a fantastic way to improve your coding skills and get into the holiday spirit!

You can read more about it here.

Why Python?

Python is a great choice for these challenges due to its readability and wide range of libraries. Whether you're a beginner or an experienced coder, Python makes solving these puzzles both fun and educational.

How to Participate?

  1. Sign Up/In.
  2. Join the r/Python private leaderboard with code 2186960-67024e32
  3. Start solving the puzzles released each day using Python.
  4. Share your solutions and discuss strategies with the community.

Join the r/Python Leaderboard!

We can have up to 200 people in a private leaderboard, so this may go over poorly - but you can join us with the following code: 2186960-67024e32

How to Share Your Solutions?

You can join the Python Discord to discuss the challenges, share your solutions, or you can post in the r/AdventOfCode mega-thread for solutions.

There will be a stickied post for each day's challenge. Please follow their subreddit-specific rules. Also, shroud your solutions in spoiler tags like this

Resources

Community

AoC

Python Discord

The Python Discord will also be participating in this year's Advent of Code. Join it to discuss the challenges, share your solutions, and meet other Pythonistas. You will also find they've set up a Discord bot for joining in the fun by linking your AoC account.Check out their Advent of Code FAQ channel.

Let's code, share, and celebrate this festive season with Python and the global coding community! 🌟

Happy coding! 🎄

P.S. - Any issues in this thread? Send us a modmail.


r/learnpython • • 2h ago

pulling the same fields off a bunch of venue sites and now every site has its own parser, is there a saner way

5 Upvotes

same stuff on every venue site. name, date, price, ticket link. but each one hides it somewhere else, a table on one, cards on another, and a couple only fill in after the js runs so those go through playwright

so now theres a parser per site, and when a venue redesigns i find out because my list goes quiet

do people just live with one parser per layout or is there a way to describe the fields once​


r/learnpython • • 17h ago

Can logging replace my verbosity controls?

11 Upvotes

An old habit from C days is to add print statements for debug and assign them different verbosity levels. I've been doing that in Python as well.

if verbosity > 2:
    print("This level generates a lot of output, so use it sparingly")

I've been told that the logging facility is the Python way to do this, so I'm finally investigating it. What I'm seeing is that the levels are DEBUG, INFO, WARNING, ERROR which doesn't really fit what I want to happen. Everything I want to put under verbosity control is technically DEBUG or INFO.

So my question is: are there sublevels on the DEBUG or INFO logging? Or is there another approach for this sort of thing?

EDIT: Still reading. I think the answer might be a hierarchy of loggers and filters? Trying to figure out how that works now.


r/learnpython • • 7h ago

need help with this lab

5 Upvotes

Write a program that will combine two integer arrays into one larger array and remove any duplicate values.
Prompt the user for a number N, (N will be a positive integer greater than 1), then create two arrays each with N elements. Next, populate both arrays with random numbers between 0 and
500. Finally combine the two arrays into a third array making sure that only distinct values are added. I.e. if the number '65' exists in both arrays, only one instance of it will be added to the third array.
Your program should output contents of the third array, one number per line.
Before you hand it in, make sure to test your program with an A value of:
• 10
25
50
Input:
N: 25
Output:
The contents of the final array, one number per line.