r/learnpython 11h ago

I'm a beginner. can you help me with random numbers?

16 Upvotes

I'm building a sort of turn-based RPG in the terminal as a practice project, and I need to generate a random number within a specific range. I tried using `randint` (by importing `random`), but I also want to assign probabilities so that, depending on certain factors, one number is more likely to be generated than another. For example, if an enemy has low health, it should be more likely to generate the number 1, which causes the enemy to heal.


r/learnpython 16h ago

I need learning python for robotic

8 Upvotes

I'm really desperate, I have a college project where I need to present at least one movement algorithm based on a Cartesian plane. I've already been introduced to Python, but I can't say that's my strong point, I'd like to know recommendations for study materials, or where to start!! Thanks you 😔😔


r/learnpython 17h ago

Ignore certain keys when comparing two dicts

3 Upvotes

Disclaimer: I'm not a developer, just a network engineer that can spell Python correct about 60% of the time.

I have a script that collects current neighborship data on a router (CDP, LLDP, OSPF, EIGRP, etc.) and compares it to a known good baseline (neighborship data that was collected and stored at a time when all expected neighborships were up). The data is collected into a dictionary object that stores the local interface a neighbor is known on and the neighbor's IP or hostname as key-value pairs (e.g. `{'HundredGigE1/0/1':'RouterA'}`). If all expected neighbors are up (e.g. `if collected_data == device_baseline`), the report generated notes that the current state matches the baseline; otherwise, it goes through the current data and baseline and notes any added/changed/missing neighbors.

I'm wanting to add tracking to this--when the script runs and grabs the current data, if it matches the baseline, I want a timestamp stored next to it, maybe something like `{'HundredGigE1/0/1': {'name':'RouterA','last_up':<current_timestamp>}}`. That way if an expected neighbor is currently down, I can have the report note the last time it was up. (I currently have the script run a sweep/collect function every 10 minutes but not generate a report, so the data would be relatively current. At present it is just checking whether devices are online, not actually logging into anything and pinging it. We have monitoring solutions, a syslog server, etc. and this isn't meant to replace those in terms of real-time data, it is just for generating a daily overview report.)

If I structure the data this way, it would break the equality check I use to check for the current data matching the baseline; even if all expected neighbors are up, the timestamps would not match. Would the best way to work around this be to just create a copy of the baseline and current data and pop the timestamp field out, or is there a more elegant way for a comparison operation between dicts to ignore the timestamp key?


r/learnpython 20h ago

What is the best way to learn Python as a beginner?

3 Upvotes

Hi everyone! I’m a complete beginner in Python and I want to learn it from scratch. I’m not sure where to start or which resources and projects would be best for me.

What learning path would you recommend for a beginner? Any tips, courses, YouTube channels, or practice websites would be appreciated. Thank you!


r/learnpython 21h ago

Does asyncio have a built-in feature for graceful shutdown (and preventing duplicate task execution)?

2 Upvotes

Multiple pods, each an asyncio worker pulling jobs from a shared queue (Redis/SQS-shaped). On scale-down/deploy I want to stop pulling new jobs and let running ones finish - is there anything in asyncio itself for this?


r/learnpython 1h ago

My login/account creation system in Python, part of a bigger project I'm building as I learn

Upvotes

This is a console based account system I've been building as I learn Python. Right now it lets you create an account with username and password rules (length limits, and the password needs a letter, a number, and a special character), log in with a 3 attempt lockout, and pick from a simple menu.

It's a work in progress and part of a bigger project. Next I want to add a to-do list and notes, then save the data to a file, and eventually hash the passwords instead of storing them as plain text.

The three password checks are repetitive. I haven't learned functions yet so I did them the long way with separate loops. I already know functions are the fix and that's my next topic, so you don't need to only point that out, but any other feedback is welcome.

I used AI (Claude) as a tutor to understand concepts and point me toward my own bugs, but I wrote and debugged every line myself. I'm learning how to code through the MOOC.

GitHub: https://github.com/mart23inez/Personal-Account-System/tree/main

What would you improve or build next?


r/learnpython 2h ago

[Python / Playwright / Selenium] Need help solving a visa appointment problem

1 Upvotes

Hi everyone.. I'm an Egyptian student accepted for a Master's at Sapienza University of Rome, starting September 21, 2026.

My documents and university procedures are ready, but I'm unable to secure an Italian student visa appointment through AlmavivA Egypt.

Appointments are released daily around 9 AM, but they disappear extremely quickly. There are also brokers/scalpers who use automated tools to secure appointments much faster than normal users, then resell them to students.

I'm not looking to buy an appointment or build a tool to resell them. I just need help from someone experienced with Python / Playwright / Selenium / browser automation to understand if there's a legitimate technical solution that could give me a fair chance of securing one appointment for myself.

If you have experience with this kind of automation and can help or point me in the right direction, I'd really appreciate it.. I'm genuinely worried about missing my Master's start date because of this.

Thank you 🙏


r/learnpython 8h ago

Python difference.

3 Upvotes

What is the difference between python ,IronPython,Jython,Cython.i will get a lot of confusion towards these concepts.


r/learnpython 12h ago

recursion problem

1 Upvotes

I'm trying to teach myself python using John Zelles book. On the 13th chapter it gives this example of recursion I'm trying to understand:

def moveTower(n, source, dest, temp):

if n ==1:

print("move disk from , " , source , "to", dest)

else:

moveTower(n-1, source, temp, dest)

moveTower(1, source, dest,temp)

moveTower(n-1,temp,dest,source)

def hanoi(n):

moveTower(n , "a", "c","b")

hanoi(3)

The code is first assiging the variables A to source then C to dest then b to temp but do the lines moveTower(n-1, source, temp, dest) and moveTower(n-1,temp,dest,source) work? Would it be moveTower(3-1, a,b,c)? How exactly are they outputting a to c then a to b then c to b and b to a , etc...


r/learnpython 1h ago

Is there any app better than Pydroid 3 and Acode?

Upvotes

Is there a better Python development environment for Android? 🐍📱

I'm a Python developer who does most of my development on an Android phone, mainly using Pydroid 3/Pyramid and Acode.

I've found that neither is really ideal for my use case:

Pydroid 3/Pyramid: Some native/compiled libraries such as TensorFlow, PyTorch, OpenCV, etc. can work, but some frameworks such as Flet/NiceGUI don't work properly. Some packages/features also require a subscription.

Acode: It's great for editing and web-based/server-style frameworks such as Flet/NiceGUI, but native-heavy libraries such as TensorFlow, PyTorch, OpenCV, Kivy, etc. are difficult or impossible to use in my setup.

So I basically have to switch environments depending on the project.

Is there any better/free Python development environment for Android that can handle a wider range of Python packages and frameworks?


r/learnpython 9h ago

Help me code a movie selector!

0 Upvotes

Hi all, new to Python and for my first project I'm trying to code a program that will randomly select a movie or tv show using a pre-made list, and a "genre" plus "media type" as input.

I feel I am over complicating it.

Here's where I'm at so far:

def media_selector(media, genre):
### attempting to remove previously selected titles and for some reason make my own RNG \/###
increment = + 1
trans_rng = [1, 2]
genre = ['romance', 'action']
movie_list = ['rango', 'taxi driver']
series_list = ['akira', 'trigun']
### spell check, obviously \/###
spell_check = ['film', 'movie', 'tv show', 'tv series', 'tv', 'romance', 'action']
if not isinstance(media, str):
return 'format is: media type, genre'
### not sure if i should be defining a function and calling it at the same time - also is a translation table too much ? \/###
if media and genre is (spell_check):
def media_decider():
movie_trans_tbl = movie_list.maketrans(movie_list, trans_rng)
movie_transd = movie_list.translate(movie_trans_tbl)
series_trans_tbl = series_list.maketrans(series_list, trans_rng)
series_transd = series_list.translate(series_trans_tbl)
selector = slice(increment)
else:
return 'film/movie or tv show/tv series'

any guidance/recommended resources would be greatly appreciated!


r/learnpython 15h ago

I’m taking a programming (intro to python ) class and the teacher isn’t the best in the world so I’m thinking of trying to learn on my own .Any advice I’m an extremely visual person so videos help me more than books

0 Upvotes

Thanks!!!


r/learnpython 19h ago

Best way or roadmap for Python

0 Upvotes

Ik python basics and all basic syntax so what would be the next thing to learn?
Can recommend and yt vid(cs50p full beginner so no)
Im trying freecodecamp yt videos are there any other videos u would recommend?
Also im interested in web dev so help me out with this as well or should i try out a different language?


r/learnpython 16h ago

Is this realistic? Easy? Impossible? Cumbersome?

0 Upvotes

TLDR: how feasible is it to make an extremely rudimentary “app” solely for personal use using only an iPhone and iPad (with occasional access to a friend’s Macbook), that can be used and updated on (/across multiple) iOS devices?

~ ~ ~ ~

I have next to no knowledge of code but I’m a good learner and love a new project. I want to make myself a gamified productivity(etc.) “application” that only needs to be for personal use. Just me. And honestly it can start just as a rudimentary glorified to do list.

Ive been researching for a few days, and python seems to be the most approachable language for the job, but at this point my head is swimming a bit, and i just wanna make sure what i want is feasible before I sink any money and a lot more time lol. Id appreciate any advice!

My restrictions:
-must be easily used and updated from iOS devices. Preferably across multiple.
-I can only write/edit from iPhone and iPad, with limited access to a (family member’s) Macbook. Might be able to locate external keyboard.
-I got next to no budget lol (could possibly make small otp for something like Pythonista, MAYBE an inexpensive subscription for something).
-I want as little to do with AI as humanly possible.

How doable is what I’m imagining? The most recent possible roadblock Ive come to is that, from what ive researched, Pythonista seems like a good IDE for iOS, but I dont think id be able to use it as a reliable virtual environment(?).

Thanks in advance! ^^ <3

~ ~ ~ ~

EDIT: specified it doesnt need to be a full on app with bells and whistles. I just want to start with a glorified to do list essentially.


r/learnpython 7h ago

How do I write multiple lines of code in Python ver. 3.14?

0 Upvotes

I'm currently relearning python since it's been a long time since I touched one. But I can't seem to write multiple lines of code since it'll run 1 line of code at a time (whenever I press enter to write on a new line).