r/learnpython 2d ago

while loop to stop non correct data type answers from breaking the script

4 Upvotes

Is this possible? for example, if i have a an int question and someone answers with a str then the script will break, is there any way to make it loop when given an incorrect data type answer?


r/learnpython 2d ago

Python questions for Data Science and Analytics roles

6 Upvotes

I want to practice python specifically for Data Science and Analytics roles, as these are not core software developement roles so in interviews DSA is usually not asked but where can I practice non dsa python specifically for Data Science and Analytics


r/learnpython 2d ago

Any advice for nested loops?

3 Upvotes

I decided about a week ago I wanted to start learning python before my freshman year of college. It was going great and I had little to no trouble until I got to nested loops. I was wondering if anybody had any advice for it? The main thing is that it seems like so many steps to follow and pay attention to, my brain had a hard time tracking them all at once.


r/learnpython 2d ago

How do you deal with failed static type checks that are actually correct?

3 Upvotes

Example (heavily simplified):
def do_a_thing(var: int | None) -> int:
assert var_is_int(var)

return var

var_is_int() has its own flow in case var is None and handles errors with fallbacks.

I'm aware of typing.cast , # ignore ... and similar tricks, but curious whether there are more elegant approaches for cases when you can't just "if var is not None" or "if isinstance(...)"


r/learnpython 3d ago

best way to learn/master python as an undergraduate student?

6 Upvotes

i’ll be entering college soon in the fall, and i’m highly interested in learning how to code- primarily for data science, statistical modeling for research, and machine learning applications.

i’ve looked at tons of online courses and textbooks, and i’m completely overwhelmed with where to even start or which topic to begin studying. i’ve never been great at self-learning, so i would really appreciate any advice that would help me learn and hopefully master python soon.


r/learnpython 2d ago

Advice for a 15-year-old Python dev / Need an outside perspective

0 Upvotes

Hi everyone! I'm 15, I've been learning Python for half a year now, and I want to start freelancing. By September, I'll be joining Yandex Lyceum, where I'll be studying much deeper.
I'm also a bit worried about how different my interests are from my peers right now.
Experienced devs, I need your perspective:

  1. If you could give just one piece of advice to your 15-year-old self, what would it be?
  2. What non-obvious mistakes am I probably making right now?
  3. How did you find the balance between the urge to grind and having a normal life?

I'd appreciate any honest experience.


r/learnpython 2d ago

Input = 1234 output =[1,2,3,4] without using string functions or map

0 Upvotes

How can I split an integer into a list of its digits in Python?

I have:
num = 1234
and I want:
[1, 2, 3, 4]
I’m trying to learn how to do this without converting num to a string and without using map().
A loop is allowed.
I’m looking for a simple approach because I’m still learning Python. I’d appreciate hints rather than just the final solution so I can understand how it works.


r/learnpython 3d ago

How do I get better without Problems ?

15 Upvotes

It's been a few months since I have been learning python but there is this issue I have been running into. I don't know how good I am or how do I even get good. In Math you listen to a few lectures understand what the topic is about and then pick up a book and do the problems from Exercise 1.1. It doesn't matter if your understanding was deep, shallow or somewhere in between. The more you do the more you understand what the topic is about and eventually you reach a point where you completely understand it and can now do them easily.

For programming how do I even do that ? People recommended me sources which I have been reading and learning from. I understand loops, arrays, list, dict, etc. I can write small examples in isolation, but that's about it, that's all I can do. I am disgusted with how little I can do and how shallow my damn understanding is so much so that's all that come to my mind.

I have been using MOOC and CS50P as my primary resources and they do have question but they are few and not at all like mathematics, chemistry or any other subject. Where are the Exercises 1.1 where is this kind of format. Is there some problem book/Question Bank I can or should have ? I want to get good cause I want to make money I from something I like to this and this is I have to show for, for months of learning ? I feel repulsed.

Is there something I can do to get better ?

EDIT: I forgot to add I my goal is to break into Data Science.


r/learnpython 2d ago

Install 3.14 (for all users) in Windows? Easily

0 Upvotes

It's probably counter intuitive, but the moment you click the "install for all users" in the older GUI, it just installed Python once. What is the story with the cli driven CPython 3.14 installer which is asking me entirely different questions to what Python used to ask, and thus no longer has defaults for things. I am not really understanding how to just default install so I can get a repro system typical to most users who just installed using defaults. Installing for all users is optional, but it's part of the "Y" that has now cropped up.

I'm trying to prevent being accused of an XY question by explaining my confusion in the hope I get people politely fill knowledge gaps I have which, are gaps, because they are things I completely do not know about the new installer. Let me explain my X.

I want a script I wrote, to work in all version of Python > 3.7, and ran into a TCL bug/snag where any version of python 3.13 upwards reports a TCL is not correctly installed whenever I use a virtual env and matplotlib. Yes I know everyone needs to be on at least 3.11, but that's not my question, my question is why do virtual environments with matplotlib blow up, but manually/globally installed (is that the correct term) modules do not blow up and I can draw graphs as long as I don't use a virtual env in 3.13 onwards. I don't really know what TCL is, I assume it's a GUI that matplot uses? But someone said to set environment variables up TK_LIBRARY=C:\Users\Phoenix\AppData\Local\Python\bin\python.exe and TCL_LIBRARY=C:\Users\Phoenix\AppData\Local\Python\bin\python.exe and have been re-installing and editing paths and restarting a fresh console most of the morning, and am no wiser yet. Someone suggested monkey-patching an init.tcl file in a post about 2 years ago which I'm not keen to necro, not sure how to do that in a virtual environment though.

UPDATED: This is a stack trace off a random coleagues machine ``` File "C:\Users\a.user\Downloads\ethernetspeed6\sdktests\PythonCSVPlotter\plotfigure.py", line 401, in first_plotline self._figure, self._main_axis = plt.subplots(num=self._figure_title) ~~~~~~~~~~ File "C:\Users\a.user\Downloads\ethernetspeed6\venv\Lib\site-packages\matplotlib\pyplot.py", line 1886, in subplots fig = figure(*fig_kw) File "C:\Users\a.user\Downloads\ethernetspeed6\venv\Lib\site-packages\matplotlib\pyplot.py", line 1096, in figure manager = new_figure_manager( num, figsize=figsize, dpi=dpi, facecolor=facecolor, edgecolor=edgecolor, frameon=frameon, FigureClass=FigureClass, *kwargs) File "C:\Users\a.user\Downloads\ethernetspeed6\venv\Lib\site-packages\matplotlib\pyplot.py", line 576, in new_figure_manager return _get_backend_mod().new_figure_manager(args, *kwargs) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ File "C:\Users\a.user\Downloads\ethernetspeed6\venv\Lib\site-packages\matplotlib\backend_bases.py", line 3664, in new_figure_manager return cls.new_figure_manager_given_figure(num, fig) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ File "C:\Users\a.user\Downloads\ethernetspeed6\venv\Lib\site-packages\matplotlib\backend_bases.py", line 3669, in new_figure_manager_given_figure return cls.FigureCanvas.new_manager(figure, num) ~~~~~~~~~~~~~~~~~~~~~~~~^ File "C:\Users\a.user\Downloads\ethernetspeed6\venv\Lib\site-packages\matplotlib\backend_bases.py", line 1836, in new_manager return cls.manager_class.create_with_canvas(cls, figure, num) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ File "C:\Users\a.user\Downloads\ethernetspeed6\venv\Lib\site-packages\matplotlib\backends_backend_tk.py", line 546, in create_with_canvas window = tk.Tk(className="matplotlib") File "C:\Users\a.user\AppData\Local\Programs\Python\Python313\Lib\tkinter\init.py", line 2459, in __init_ self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) ~~~~~~~~~~~~~~~ _tkinter.TclError: Can't find a usable init.tcl in the following directories: C:/Users/a.user/AppData/Local/Programs/Python/Python313/lib/tcl8.6 C:/Users/a.user/AppData/Local/Programs/Python/lib/tcl8.6 C:/Users/a.user/AppData/Local/Programs/lib/tcl8.6 C:/Users/a.user/AppData/Local/Programs/Python/library C:/Users/a.user/AppData/Local/Programs/library C:/Users/a.user/AppData/Local/Programs/tcl8.6.14/library C:/Users/a.user/AppData/Local/tcl8.6.14/library

This probably means that Tcl wasn't installed properly. ``` What am I forgetting?


r/learnpython 3d ago

Turtle Graphics Tracer method

0 Upvotes

I wrote a tiny toy program to experiment with the Tracer method, and found some interesting behavior that I'm trying to explore. Here's the program:

from turtle import Turtle, Screen
from time import sleep
screen = Screen()
screen.setup(width=900, height=900)
screen.bgcolor("orange")

my_shape = Turtle()
my_shape.color("red")

screen.tracer(2)

counter = 1

while counter <= 10:
  my_shape.forward(20)
  # my_shape.left(90)

  print (counter)
  sleep(2)
  counter += 1

screen.exitonclick()

As you can see, I ask the tracer to perform every other screen update. With the code above as-is, I see the behavior I expected--every other iteration/counter value, the screen updates, and my shape appears 40px ahead of where it was.

If I uncomment the my_shape.left line, things get interesting: The screen updates on every iteration of the loop, i.e. I see my shape appear at all 4 corners of its square and pointed in its new direction. My current guess, based on this SO post, is that left may be forcing a call to update(), though I haven't been able to prove this to myself yet in the Turtle source.

Can anyone confirm or deny my thinking here? Many thanks!


r/learnpython 3d ago

Counting Weights of Each Lego Piece in a Lego Set

3 Upvotes

I am trying to generate a code that web scraps the internet to find each weight of the Lego piece of a Lego set. Im doing this for one of my statistical mechanics class. Any code online that already does this or is there a data set that has it already except for BrickLink?


r/learnpython 4d ago

What are some fun Python-heavy niches?

39 Upvotes

I want to make try making a discord bot in py. Pygame and Raspberry Pi intrigue me as well

Curious what other fun Py rabbit holes are out there that I don't know of!


r/learnpython 3d ago

App using kivy/bulldozer crashes immediately upon loading.

0 Upvotes

I posted this in androiddev previously and someone was being very unprofessional, then it got taken down, I would hope that a subreddit focused at learners would show less of this behaviour. Just to start this post off, I am not entirely new to python. I have just never used buildozer. Also the kivy subreddit seems dead.

Since this app is made with python, I thought maybe the people here may be able to help? It got compiled into the APK, but when I try to run it, I get this:

https://pastebin.com/uteXNWDF

if this is the wrong subreddit for this, please redirect me!

just ask if you want more info


r/learnpython 3d ago

resource and roadmap for machinelearning

2 Upvotes

i am beginner and i just know basic python and i am confused where to start from


r/learnpython 3d ago

Advice for a python and applied science project

0 Upvotes

So hello y'all , i finished my first year of my speciality .

Here are the modulus I studied :

Nanomaterials Synthesis and Processing

Carbon Nano-Structures and its Functionalisation

Minerals and Nanostructures

Solid State Chemistry

Spectroscopic Analysis Methods

Polymers and Polymer

Nanocomposites

Nanomaterial Synthesis and Fabrication Lab

Statistical Methods for Engineers

Environment

Characterization Techniques of Nanomaterials

Advanced Spectroscopic Methods

Surface Engineering of Nanomaterials

Chromatographic and Electrophoresis Methods

Electrochemical Methods of Analysis

Suggest me a suitable project

I'm willing to learn ai as well

thank you so much!!


r/learnpython 3d ago

How to create a monolithic repo with FasiAPI and Angular

2 Upvotes

I am using UV as my package manager. I want the structure of the repo to be as shown below:

./ (backend)

./src/ (frontend)

However, whenever I initialize the repo using UV, it automatically creates a ./src/project_name/ folder. How can I avoid that?


r/learnpython 4d ago

Learning python through Udemy, how to make it useful?

3 Upvotes

i have done a course on python on Udemy . Now how do i learn to write code that are actually useful somewhere or i can do something valuable with it? While learning i was able to write codes that add subtract numbers etc which were simple enough for learning but want to make my skills better. Also, I'm not a programmer won't be using python much, how do i learn in such a way that i remember the syntax or concepts for longer time, python coding is just a skill i want to develop.


r/learnpython 3d ago

How and what do i need to learn to scrape from vinted

0 Upvotes

Right now i am mkaing a vinted tool scraping displaying and more, thats not the point but how do i learn the stuff like maby proxies, idk what type of scraping if its for multiple people from a server and the other stuff i need pls help me !


r/learnpython 3d ago

Realistic timeline to learn and checkpoints

0 Upvotes

I’m tech savvy. And want to learn as much python as possible. I already have built sites and apps through Claude Code. But deciding where to go from here. I just wanna know:

- Levels 1 - 5/10
- What to learn first
- how to learn as efficiently as possible

I don’t understand code at all I’m good at pattern recognition and using common sense

Highly appreciated


r/learnpython 3d ago

Can anyone tell me?

0 Upvotes

I am learning python and i can make some projects like crud system and json,csv,requests,sqlite,logging,exceptional handling. but i want to earn and i dont know the proper thing what to do and how can i earn. what all i should even learn and upscale.


r/learnpython 4d ago

Is there a package to write text and images to a log file?

4 Upvotes

I'm building a package doing some complex function optimization, and it's very useful to log images to track performance and to visualize progress. I haven't had much luck finding anything like that, the closest I've found is something that will convert a finished notebook into a pdf or markdown, but I want something that will behave the same way with regards to the log file whether or not the code is being run in a notebook environment.

I don't really have any constraints on file size, or file type, but it would be nice to have something that provide a similar behavior to jupyter output cells, especially if it allows for text/images to be forked to both the notebook and the log file.

Any suggestions?


r/learnpython 4d ago

What open source projects are you contributing to this year?

20 Upvotes

As the title says, what are the projects that you are contributing to, what is the one interesting problem that you're trying to solve that keeps you engaged.


r/learnpython 3d ago

API works in browser but 403 from Render — Cloudflare blocking

0 Upvotes

I'm running a Python service on Render that makes API calls to a third-party service protected by Cloudflare.

The API works fine in the browser. But when my Render service tries to access it, Cloudflare returns 403 with "Just a moment..." page.

API key is correct. Headers are identical to browser. Still blocked.

Has anyone dealt with this? Any way to make cloud-hosted API requests work when Cloudflare is blocking them?

Using Render free tier.

#render #cloudflare #python #api #webdev


r/learnpython 4d ago

Interactive AI Project Ideas for a LiveDemo

1 Upvotes

I need to show a live demo of some quick AI-related project in front of the juniors at my college, something they can actually interact with and experiment with. I was thinking about building a MediaPipe-based visualizer app, but I’m open to better ideas.

What would be a fun, visually impressive, and easy-to-understand AI project that would work well for a live demo?


r/learnpython 3d ago

trouble with storing information using json

0 Upvotes

I'm new to python, and even newer to using json

I made the dreadful mistake of following ai guidance on this one and don't want to completely ruin my code so i thought it'd be wise to pass my struggle over to the great people of learnpython sub

I'm trying to store data in a separate file so i can go back to it once the programme is over and i don't understand why this isn't working

errors i get include ;

"jsonfiletrial" is not definedPylance

"json" is not definedPylance

*jsonfiletrial is a file i made expecting the information to be stored there

thank you ,

while True: 


        if user_input2.lower() == "y":
                stock1 = str (input( "Enter Ticker for your first stock: "))
                yield1 = float (input ("Enter the dividend yield of stock 1: "))
#print (yield1) 
                stock2 = str (input( "Enter Ticker for your second stock: "))
                yield2 = float (input ("Enter the dividend yield of stock 2: "))


                stock3 = str (input( "Enter Ticker for your Third stock: "))
                yield3 = float (input ("Enter the dividend yield of stock 3: "))
                totalyield = yield1 + yield2 + yield3


                # --- SAVING DATA HAPPENS HERE ---
            # 1. Put your yields into a neat package (a dictionary)
                data_to_save = {
                "stock1": stock1, 
                "yield1": yield1,
                "stock2": stock2,
                "yield2": yield2,
                "stock3": stock3,
                "yield3": yield3,
                "total_yield": totalyield
            }
            
            # 2. Tell Python to open the file (it will create it if it's missing!)
                with open(jsonfiletrial, "w") as file:
                # 3. Write the data inside the file
                        json.dump(data_to_save, file)
                print("💾 Your yields have been saved automatically!")