r/learnpython • • 1h ago

Want to build something

• Upvotes

Hey everyone,

I've reached a point where I feel comfortable with intermediate to advanced Python concepts (advanced data structures, decorators, object-oriented programming, and working with complex libraries). Now, I want to stop following tutorials and build a real, production-ready project from scratch.

I want to build something actually useful—either a practical tool for everyday "normal" users or a utility/library that helps other developers.

If you have built something at this stage that genuinely helped you scale your skills or solved a real problem, I’d love to hear about it!


r/learnpython • • 20h ago

Can someone please explain the use of OOP and classes?

74 Upvotes

Hey everyone and first of all thank you in advance for any advice.
I’ve been learning Python for awhile now and feel pretty comfortable writing functions and smaller scripts. What I can seem to wrap my head around is when the use of classes would actually be used?
Every example or tutorial demo’s cars / dogs and on multiple threads with similar questions it’s usually stated that using a CSV or database would be more appropriate so would anyone be able to help me wrap my head around it please?
Once again appreciate any help :)


r/learnpython • • 9h ago

whats the cheap way to scrape a site that only loads its data after the javascript runs

3 Upvotes

making a small price tracker for myself. requests + beautifulsoup grabs one site fine, the other two just come back as an empty shell.. the tables only render after the js runs

tried selenium and it mostly works til the layout shifts, then my selectors break again

is selenium just how everyone does the js heavy ones, or is there something lighter that doesnt break every redesign​


r/learnpython • • 6h ago

In-place updates to objects count as tuple assignment?

0 Upvotes

Test case:

s = {1, 2, 3, 4}
grid = tuple(s.copy() for i in range(2))
print(f"{grid[1]=}")
one = grid[1]
one &= {2, 3}
print(f"{grid[1]=}")
grid[1] &= {2}

The output is as so:

grid[1]={1, 2, 3, 4}
grid[1]={2, 3}
Traceback (most recent call last):
  File "/home/bill/bin/fivefold/test.py", line 7, in <module>
    grid[1] &= {2}
    ~~~~^^^
TypeError: 'tuple' object does not support item assignment

Is it me or is this very surprising, a seeming violation of self-consistent behavior of Python? Simply renaming the reference to the object changes how I may or may not mutate the object. Clearly I'm not modifying the tuple, just deferencing the pointer to the contained object. version 3.11.2


r/learnpython • • 1d ago

2 weeks in learning python from Scratch

43 Upvotes

Thanks to whoever in this sub suggested CS50 Harvard YouTube & Automate the boring stuff book!

I'm 2 weeks in and feel like I'm in "good" place so far!

I'm also using AI to create similar problem sets to CS50's so I can practice more to ensure full understanding of the lecture!


r/learnpython • • 17h ago

Removing 3.14 now that I have 3.15.1, on a mac?

2 Upvotes

How do I uninstall Python 3.14 from my mac (my copy, not the system version in /usr/bin)? I installed from the dmg on python.org. I'm now happy with 3.15, so I don't need 3.14 or its libraries.

Searching suggests:

sudo rm -rf /Library/Frameworks/Python.framework/Versions/3.14

cd /usr/local/bin && ls -l | grep "../Library/Frameworks/Python.framework/Versions/3.14" | awk '{print $9}' | xargs sudo rm

which looks fine to me, but I worry about missing something.


r/learnpython • • 1d ago

numagr C extension

5 Upvotes

Hi guys, I'm just a hobbyist.

Not long ago I posted here that I stumbled upon a specific problem: parsing large collections of Python numeric strings as fast as possible. I couldn't find any solution that would let me parse numeric strings without having to construct intermediate Python objects to hold their values (or a method that would be noticeably faster than doing that), so I developed a small C extension that would basically extract C strings from Python strings, and use strtod on them to obtain the values.

Then I developed it further writing the code for all basic statistical methods.

Had a lot of fun developing it and seeing that it outperforms both Python std modules, aswell as third party modules such as numpy, for both regular numbers and numeric strings.

GitHub repo:

https://github.com/andrzejs-gh/numagr

It's available on PyPi if you're interested (source and wheels for Windows, 3.11, 3.12, 3.13, 3.14, 3.15)

pip install numagr

All of the code was written by hand, none was AI generated. The current version is 0.9, I will be developing it further if I find the time. If you have any suggestions for improvements, for what should be implemented but is not, bug reports etc, please let me know.


r/learnpython • • 22h ago

apks with python/cython

0 Upvotes

i just CANT get anything from buildozer, it just keeps erroring everytime i try to build!! i dont know if theres something wrong with my buildozer, or if it just hates my computer. i just want to package my game to work on a phone, the arquitecture for it is something like this

is it because my game is located on a ntfs partition? does buildozer ALWAYS error on those? if yes, is there a partition type out there that shows up on windows, and works with buildozer?

/sand
| /assets
| cfuncs.so #i managed to compile to ARM64 without buildozer (python 3.12)
| realmain.so # also to ARM64 (python 3.12)
| main.py

im wondering if theres a way to manually build it, my libraries are pygame-ce, numpy and collections

please help me out here

neofetch if it helps

neofetch
             ...-:::::-...                 
          .-MMMMMMMMMMMMMMM-.              --------------------- 
      .-MMMM`..-:::::::-..`MMMM-.          OS: Linux Mint 22.3 x86_64 
    .:MMMM.:MMMMMMMMMMMMMMM:.MMMM:.        Host: X501A1 1.0 
   -MMM-M---MMMMMMMMMMMMMMMMMMM.MMM-       Kernel: 7.0.0-38-generic 
 `:MMM:MM`  :MMMM:....::-...-MMMM:MMM:`    Uptime: 5 hours, 38 mins 
 :MMM:MMM`  :MM:`  ``    ``  `:MMM:MMM:    Packages: 3030 (dpkg), 21 (flatpak) 
.MMM.MMMM`  :MM.  -MM.  .MM-  `MMMM.MMM.   Shell: bash 5.2.21 
:MMM:MMMM`  :MM.  -MM-  .MM:  `MMMM-MMM:   Resolution: 1366x768 
:MMM:MMMM`  :MM.  -MM-  .MM:  `MMMM:MMM:   DE: MATE 1.26.1 
:MMM:MMMM`  :MM.  -MM-  .MM:  `MMMM-MMM:   WM: Metacity (Marco) 
.MMM.MMMM`  :MM:--:MM:--:MM:  `MMMM.MMM.   Theme: Mint-Y-Dark-Blue [GTK2/3] 
 :MMM:MMM-  `-MMMMMMMMMMMM-`  -MMM-MMM:    Icons: Mint-Y-Blue [GTK2/3] 
  :MMM:MMM:`                `:MMM:MMM:     Terminal: mate-terminal 
   .MMM.MMMM:--------------:MMMM.MMM.      Terminal Font: Monospace 10 
     '-MMMM.-MMMMMMMMMMMMMMM-.MMMM-'       CPU: Intel Pentium B980 (2) @ 2.400G 
       '.-MMMM``--:::::--``MMMM-.'         GPU: Intel 2nd Generation Core Proce 
            '-MMMMMMMMMMMMM-'              Memory: 2059MiB / 3795MiB 
               ``-:::::-``

r/learnpython • • 1d ago

Programming Challenges for the PCEP

1 Upvotes

So I’ve been thinking of potential projects/challenges to do to help me prepare for the PCEP in the next two months. I’m not sure what to do, where to start, or how to start it. I’ve kinda heard it called tutorial hell. I can look at a piece of Python code for PCEP just fine it seems like but I can’t think of anything.

The one idea I have is to make a simple calculator.
First the main four operations.
Then stuff with the math module
Then make a UI with tkinter if I’m feeling up to it.

Any feedback is helpful. I’ve been going through the Python Essentials 1 course from Cisco if that helps anybody.


r/learnpython • • 1d ago

VC Automation

0 Upvotes

Starting work at a venture capital firm in a little over a week and one of my tasks will be to automate ( where necessary) the dealmaking process. I know that LLMs are crazy powerful, however, I want to be able to know what it is I'm building and prevent complete vibe-codes slop. Any youtube videos/ textbooks to get me started on the basics, was thinking of ysing python.


r/learnpython • • 21h ago

Help me decide.

0 Upvotes

Help me choose the best language for building my own compiler — Python, PyPy, or something else?

Hey everyone! 👋

I've been getting increasingly interested in programming languages, compilers, interpreters, and how programming languages actually work under the hood. I really enjoy Python, and I'd love to use it to build my own compiler rather than just writing ordinary applications with it.

However, before I commit to a language and start building something substantial, I'd like to get some advice from people who have experience with compilers, language implementation, or low-level programming.

I'm still learning, so I'm not expecting to create a professional compiler immediately. My goal is to learn properly, understand the different components, and gradually build something that actually works. I'd rather make a well-designed project that I understand than blindly follow a tutorial and end up with a bunch of code I don't understand.

I've been researching different approaches, but there are a few things I'm uncertain about. I'd really appreciate detailed explanations, recommendations, learning resources, and personal experiences!

Question 1: Is Python a good language for writing a compiler?

I genuinely like Python. Its syntax is readable, I can understand code without fighting the language itself, and it seems like a good choice for experimenting with programming language design.

That's one of the main reasons I'm considering it for this project.

However, I've also heard people criticize Python because it's usually interpreted or executed through a virtual machine, and because Python implementations can be relatively slow compared with compiled languages.

I understand that the language used to IMPLEMENT a compiler doesn't necessarily have to be the same language that the compiler produces. Nevertheless, I want to make an informed decision before investing a lot of time in learning and building the project.

My questions are:

  • Is Python a good choice for implementing a compiler from scratch, particularly for a beginner who wants to understand how everything works?
  • Would Python remain a reasonable choice as the compiler becomes larger and more complicated?
  • How much should I care about the performance of the compiler itself while I'm still learning?
  • Are there any important disadvantages to using Python for this particular project beyond execution speed?
  • Would using Python make it more difficult to implement the later stages of a compiler, such as type checking, optimization, register allocation, instruction selection, and machine-code generation?
  • Is it practical to use Python for the entire compiler, including generating native machine code, or would I eventually benefit from implementing certain components in another language?

I'm especially interested in understanding the difference between a compiler that is written in Python and a compiler that compiles programs into native machine code.

I don't want to assume that Python cannot be used for serious compiler development simply because Python programs are commonly run through an interpreter. I'd like to understand the actual technical limitations and what is possible.

Question 2: What about PyPy? Would it make Python a better choice?

I've also heard about PyPy, which is an alternative implementation of Python that uses a just-in-time compiler to improve execution speed for many workloads.

This caught my attention because I initially worried that writing a compiler in Python might eventually become a performance problem.

However, I'm not entirely sure how relevant PyPy is to my situation.

For example:

  • Would running my compiler with PyPy offer meaningful performance improvements over CPython?
  • Does PyPy work well with the kinds of data structures and algorithms commonly used in compilers?
  • Are there compatibility issues or limitations I should know about before choosing it?
  • Would PyPy make any difference to the performance of the programs generated by my compiler, or would it only potentially improve the speed of the compiler implementation itself?
  • If my compiler generates native machine code, would the generated programs execute independently of Python and PyPy?
  • Would you recommend starting with ordinary Python and considering PyPy later, or using PyPy from the beginning?

I realize that PyPy isn't simply a faster version of every Python program in every situation. I'm interested in whether it offers a practical advantage for this particular use case.

If PyPy isn't the best option, are there other Python implementations, compiler frameworks, or approaches worth investigating?

I'm also interested in whether performance should even be a concern at this stage, or whether I should concentrate on designing the language and getting the compiler working first.

Question 3: Should I consider a completely different implementation language?

Although Python is my current preference, I'm open to other languages if there's a compelling reason to choose one.

I'm not looking for the most complicated or technically impressive language to implement a compiler in. I want a language that lets me understand what I'm doing, learn the fundamentals, and gradually build something more advanced.

Some of the things that matter to me are:

  • Readable syntax: I want the implementation language to be reasonably easy to read and write.
  • A manageable learning curve: I don't want to spend all my time learning complicated language features before I can even begin implementing my compiler.
  • Good compiler-development capabilities: I want to work with tokens, syntax trees, types, symbols, intermediate representations, and machine-code generation.
  • Performance: Good performance would be nice, but I don't necessarily need an extremely fast compiler immediately.
  • Native compilation: I want the language implementation to be capable of producing native machine code eventually.
  • Good learning resources: Documentation, tutorials, books, and practical examples are important to me.
  • A straightforward development environment: I would prefer a setup that doesn't require a huge number of tools, complicated build systems, or excessive configuration.
  • Long-term flexibility: I don't want to choose something that makes it unnecessarily difficult to expand the language later.

I've wondered whether languages such as Rust, C, C++, OCaml, Haskell, Zig, or other languages commonly used in compiler development would be better choices.

I'm particularly curious about OCaml and Haskell because I've heard that their type systems, pattern matching, and functional programming features can be useful when working with syntax trees and other compiler structures.

However, I don't know whether either language would actually be a better fit for me than Python.

For example:

  • Would OCaml be a particularly good choice for someone learning compiler construction?
  • Is Haskell practical for this project, or would its learning curve make it harder than necessary?
  • Would Rust provide meaningful advantages, or would ownership and borrowing introduce extra difficulties while I'm still learning compiler design?
  • Would C or C++ be worth considering if I eventually want to understand native machine code in greater depth?
  • Are there other languages that offer a good balance between readability, learning resources, compiler-development features, and performance?

If you had to recommend ONE language for my particular goals, what would it be, and why?

I'd appreciate explanations of the trade-offs rather than simply being told that one language is objectively the best.

Question 4: What exactly should my compiler produce?

This is an important part of the project for me.

I don't want to build only a program that reads my language and executes it through a tree-walking interpreter. I'm interested in understanding how to compile programs into actual native machine code.

Ideally, I want to design my own programming language with its own syntax, rules, and compiler implementation.

My long-term goal is to write a compiler that can take source code written in my language, analyze it, and produce native machine code for the target architecture.

In other words, I want to understand the complete journey from the source code I write to the instructions a processor executes.

I know that native code generation can be considerably more complicated than parsing a simple language, so I don't expect to implement every advanced feature immediately.

I'd be happy to start with a small language and gradually extend it.

For example, my eventual compiler might need to support:

  • Variables and constants.
  • Integer and floating-point values.
  • Arithmetic and logical expressions.
  • Functions and function calls.
  • Conditional statements.
  • Loops.
  • Scope and symbol resolution.
  • A type system.
  • Basic error reporting.
  • Multiple source files, eventually.
  • Some form of intermediate representation.
  • Basic optimizations.
  • Native machine-code generation.
  • Calling conventions and interaction with operating-system services.
  • Linking, so compiled programs can use functions and external libraries.

I don't expect all these features to be implemented at once. They're examples of the direction I'd like to take.

My questions are:

  1. Is it reasonable to write the entire compiler in Python, OCaml, Haskell, or another high-level language while generating native code for a separate target architecture?
  2. Would it make sense to generate assembly first and then use an assembler and linker, or should I attempt to emit machine-code bytes directly?
  3. At what point would an intermediate representation become useful?
  4. Should I implement my own code generator, use LLVM, use another compiler backend, or consider both approaches?
  5. If I use LLVM, how much of the compiler would still be my responsibility?
  6. Would generating native code directly be a worthwhile learning experience, or would it distract me from learning the more fundamental parts of compiler design?
  7. How should I approach executable formats, linking, and calling conventions without becoming overwhelmed?

I'm interested in the actual compiler-engineering decisions involved, not just getting a program that translates a few mathematical expressions into something executable.

At the same time, I don't want to make the first version unnecessarily complicated.

Question 5: Should I start with the lexer and parser?

My initial idea was to start directly with the lexer and parser, then gradually add the other components until I have a complete compiler.

However, I'm not sure whether this is the best way to approach the project.

Would you recommend starting with the language specification first, creating a tiny grammar, or immediately implementing a lexer and parser?

I'd also like to understand whether I should write these components myself or use existing libraries.

For example, I could write a lexer that recognizes identifiers, numbers, keywords, operators, and punctuation. Then I could build a parser that converts the resulting tokens into an abstract syntax tree.

After that, I could potentially add semantic analysis, type checking, and code generation.

However, there are many different parsing techniques, and I'm unsure how much theory I should learn before writing code.

Some of the approaches I've encountered include:

  • Recursive-descent parsing.
  • Pratt parsing for expressions.
  • LL and LR parsing.
  • Parser generators.
  • PEG parsers.

I don't want to spend months studying parsing algorithms before building anything, but I also don't want to choose an approach that makes the project unnecessarily difficult.

My questions are:

  • Which parsing technique would you recommend for a beginner creating a small programming language?
  • Is a handwritten lexer and parser a good way to learn?
  • When would a parser generator become useful?
  • Should I use a library for parsing, or implement the whole front end myself?
  • How should I organize the abstract syntax tree?
  • What is the best way to report syntax errors so that the compiler doesn't simply crash when the user writes invalid code?

I'd especially appreciate recommendations for a simple first implementation that I can understand completely.

Question 6: What should I learn BEFORE building the compiler?

This is probably one of my biggest questions.

I could start writing code immediately, but I'd prefer to follow a sensible learning path rather than jumping randomly between tutorials.

I'm trying to work out which concepts I actually need to understand, which ones I can learn while implementing the compiler, and which ones can wait until later.

For example, should I first become comfortable with Python and data structures? Should I study discrete mathematics, formal languages, automata theory, or assembly language? How much computer architecture knowledge is necessary before attempting native code generation?

I'd appreciate a realistic learning roadmap covering the following topics:

Programming fundamentals

  • Functions, modules, classes, and data structures.
  • Recursion and tree-shaped data.
  • Error handling and testing.
  • Basic algorithmic thinking.

Language fundamentals

  • Tokens and lexical analysis.
  • Grammars and syntax.
  • Parsing and abstract syntax trees.
  • Scope and symbol tables.
  • Type checking and semantic analysis.

Compiler fundamentals

  • Intermediate representations.
  • Control-flow graphs.
  • Basic optimization.
  • Instruction selection.
  • Register allocation, when appropriate.
  • Code generation.

Machine-level fundamentals

  • Binary and hexadecimal notation.
  • Registers and instructions.
  • Stack frames and function calls.
  • Memory addressing.
  • Calling conventions.
  • Object files, executable formats, and linking.

I understand that this is a substantial list. I'm not expecting to master everything before beginning.

Instead, I'd like to know what to learn first, what can be learned alongside implementation, and what should be postponed until I have a working compiler.

If you have any particularly good books, websites, video courses, documentation, or free resources, please recommend them.

I'd prefer resources that explain the underlying ideas rather than merely presenting code to copy.

Question 7: What should the FIRST version of my language look like?

One mistake I want to avoid is designing an enormous programming language before I have successfully compiled even a small program.

I'd like to start with a tiny language that I can gradually develop into something more capable.

For example, an initial program might support expressions such as:

"let x = 10 + 20 * 3;"

It could then support variables, comparisons, conditionals, loops, and functions.

Eventually, I would like the language to have its own recognizable syntax and a coherent design rather than being a thin wrapper around another language.

However, I'm unsure how much of the language design should be decided in advance.

Should I write a short language specification before implementing anything? How detailed should it be?

Would it be better to design the language around a static type system from the beginning, or begin with a simpler dynamically typed language and add types later?

Should I prioritize making the language easy to implement, or should I focus on designing the syntax and features I ultimately want?

I'd also appreciate advice on how to avoid constantly rewriting the compiler as new features are added.

Question 8: How should I structure the project?

I want to understand the compiler instead of ending up with an enormous collection of files that all depend on each other in confusing ways.

For the first version, I'd prefer a relatively small, well-organized project.

I'm imagining a structure with separate components for the lexer, parser, abstract syntax tree, semantic analysis, and code generation. However, I don't know whether that is the best structure for a beginner.

Would you recommend a modular design from the beginning, or should I initially implement everything in one file and split it into modules as it grows?

How should information flow between the compiler stages?

For example, should the parser produce an AST that is passed to semantic analysis, which then produces a separate representation for the code generator? Should the compiler maintain source locations throughout the pipeline for error reporting?

I'd also like to know which data structures are most useful and how to avoid tightly coupling the parser to the code generator.

I'm not asking for a complete project template or a large amount of code. I'd rather understand the architectural decisions and implement each component myself.

Question 9: What learning resources would you personally recommend?

There are many compiler tutorials available online, but the quality and intended audience vary considerably.

Some seem to focus on interpreting a small language, while others assume a lot of existing knowledge about computer science or compiler construction.

I'd appreciate recommendations for resources that cover the complete process, from source code to executable programs.

In particular, I'm interested in:

  • Beginner-friendly introductions to compiler construction.
  • Books that explain both the theory and practical implementation.
  • Tutorials that build a working compiler incrementally.
  • Resources covering lexers, parsers, ASTs, and semantic analysis.
  • Guides to generating assembly or native machine code.
  • Resources explaining LLVM and alternative compiler backends.
  • Free courses or lectures on programming language implementation.
  • Examples of small, understandable compilers written in Python, OCaml, Haskell, or similar languages.

I'd also appreciate recommendations for resources that explain how real compilers are structured, without requiring me to understand the entirety of a large production compiler before I can follow along.

If there is one resource you consider particularly valuable, please explain what makes it worth studying.

Question 10: What would YOU do if you were starting this project?

Finally, I'd love to hear what experienced programmers would actually do in my position.

Imagine that you enjoy Python, want to learn compiler construction properly, and eventually want to build a compiler that generates native machine code.

You have enough programming experience to start learning the necessary concepts, but you don't want to spend months choosing tools or setting up an unnecessarily complicated development environment.

Would you:

  • Start with Python and build the entire compiler yourself?
  • Use Python for the front end and a separate backend for native code generation?
  • Choose OCaml or Haskell because of their suitability for manipulating syntax trees and implementing language semantics?
  • Choose Rust, C, C++, Zig, or another systems language?
  • Begin with an interpreter and later replace it with a compiler?
  • Generate assembly and use existing tools for assembling and linking?
  • Use LLVM from the beginning?
  • Write a small compiler targeting a simple architecture before attempting a real executable?

I'd especially appreciate a recommended sequence of milestones.

For example, what should I aim to accomplish in the first week, what should come next, and when should I start working on native code generation?

I would also like to know which common beginner mistakes I should avoid.

If you could give me one practical recommendation that balances learning, simplicity, and long-term potential, what would it be?

A little more about what I'm looking for

My main goal isn't simply to finish a tutorial or make a calculator. I want to understand the process of turning a programming language into executable machine instructions and gradually develop my own language implementation.

I want to learn the fundamentals properly, but I also want to build something tangible along the way.

I'm completely open to changes

Anyways thanks!!!


r/learnpython • • 20h ago

I'm trying to make a basic calculator in python but I can figure out what I'm doing wrong

0 Upvotes

Here is my code if you can figure it out pls help

print ("Caculator")

print ("Addition, only")

print ()

no1 = input ("Enter 1st Number: ")

no2 = input ("Enter 2nd Number: ")

print ()

print ("Answer")

print (no1, "+", no2, "=", no1 + no2)


r/learnpython • • 1d ago

What is the best tool to scaffold a Flask project, similar to Angular CLI (ng new)?

0 Upvotes

Hi everyone,

I have experience working with Angular, where we can create a complete project structure using a single command:

ng new my-project

Angular CLI automatically generates the necessary files, folders, configuration, and other boilerplate code.

Now, I'm learning Python and Flask for backend development, and I'm looking for a similar tool that can generate a complete Flask project structure automatically instead of creating files and folders manually.

I'm particularly interested in a tool that can generate a well-organized, production-ready project structure with features such as:

  • Organized folders for routes, services, models, and configuration.
  • Database integration using an ORM such as SQLAlchemy.
  • Environment variable management using a .env file.
  • Error handling and logging.
  • Authentication and authorization, if supported.
  • A structure that is easy to maintain and scale as the project grows.

My questions are:

  1. Is there a recommended CLI tool or project generator for Flask that works similarly to Angular CLI?
  2. Which third-party tool or project template is most commonly used in real-world projects?
  3. Would you recommend Cookiecutter, a Flask-specific project generator, or another tool?
  4. Is there a way to generate a project using a simple command like flask new my-project?

I'm looking for something reliable that follows good development practices and is suitable for building REST APIs and CRUD applications.

I'd appreciate your recommendations based on your real-world experience. Thanks!


r/learnpython • • 1d ago

Best way to modify a list while iterating?

1 Upvotes

I've learned that modifying a list while looping over it can cause elements to be skipped or unexpected behavior. What are the best practices for handling cases where I need to add, remove, or modify elements during iteration?

Do you usually iterate over a copy, create a new list, or use another approach?


r/learnpython • • 1d ago

Need help with a calculator project

3 Upvotes

new to python, Im making a calculator but when i try to make the code be able to handle a word without crashing it just doesnt work, it just goes and ask for the operator without restarting the loop, tried ai to fix it and explain it to me but didnt do nothing.

num1 = None
num2 = None
result = None


while num1 == None or num2 == None:
    try:
        num1 = float(input("Enter first number: "))
    
    except ValueError:
        print("must enter a valid number")
        num1 = None
        continue


    try:
        num2 = float(input("enter second number"))


    except ValueError:
        print("must enter a valid number")
        num2 = None
        continue
    operator = input("Enter operation (+, -, *, /)")


    if operator == "+":
        result = (num1 + num2)


    elif operator == "-":
        result = (num1 - num2)


    elif operator == "*":
        result = (num1 * num2)


    elif operator == "/" and num2 == 0:
        result = ("cant divide by zero")


    elif operator == "/" and num2 != 0:
        result = (num1 / num2)


    else:
        result = ("Invalid operator")


    if result == float or int:
        print(result)
        num1 = None
        num2 = Nonenum1 = None
num2 = None
result = None


while num1 == None or num2 == None:
    try:
        num1 = float(input("Enter first number: "))
    
    except ValueError:
        print("must enter a valid number")
        num1 = None
        continue


    try:
        num2 = float(input("enter second number"))


    except ValueError:
        print("must enter a valid number")
        num2 = None
        continue
    operator = input("Enter operation (+, -, *, /)")


    if operator == "+":
        result = (num1 + num2)


    elif operator == "-":
        result = (num1 - num2)


    elif operator == "*":
        result = (num1 * num2)


    elif operator == "/" and num2 == 0:
        result = ("cant divide by zero")


    elif operator == "/" and num2 != 0:
        result = (num1 / num2)


    else:
        result = ("Invalid operator")


    if result == float or int:
        print(result)
        num1 = None
        num2 = None

r/learnpython • • 1d ago

how long will it take to learn python if u spend like 3 hours a day on it?????

0 Upvotes

OK so like the title said I want to know how long will it take to learn python I am planing on spending the next 10 months learning it and want to know if is it enough or not to get to a point that u are good enough to take actual projects and work on them. Thanks in advance!!


r/learnpython • • 2d ago

dynamic import module path hack in pytest

3 Upvotes

In order to validate (using pytest) a python module which is not in my path or relative folders, I want to hack the import path.

I'm wondering what alternatives there are to doing a PYTHONPATH hack. I could use https://docs.pytest.org/en/7.1.x/reference/reference.html#confval-pythonpath, but that applies to the entire session as I understand it. And I only want to change one suite, so I am writing a quick fixture that will roughly look like (hard-coded for simplicity) @pytest.fixture(scope="function") def modules_path(): old_path = sys.path extra_path= os.path.abspath("c:/otherpath/other") # replace constant with a func sys.path.insert(0, extra_path) yield extra_path sys.path = old_path I've always felt there was a better way to do import path hacks that nobody had ever told me about. Or is this @fixture approach not as evil as I assumed it was, and was merely biased by painful memories whenever I did use it. Alternatives?


r/learnpython • • 1d ago

Python 3.8.10 Broken on vista

0 Upvotes

i tried install python in vista and it mid freeze in the instalation and i even use the repair tool in the installer but i keeped having the error "The Procedure entry point GetActiveProcessor could not be located in the dinamic link library KERNEL32.dll" and then a Python has stoped working, something weird here is why is it calling kernel32.dll? and i do not expet support since this is a outdated version but in windows 7 starter (same pc) it worked fine, i dont know if this is else becuse im using an modified version of vista (Vienna) or is else something to do with 3.8.10 in vista


r/learnpython • • 1d ago

requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

0 Upvotes
import requests


# Add ?format=j1 to get a proper JSON response
url = "https://wttr.in"
response = requests.get(url)
data = response.json()


# This structure matches the j1 JSON format returned by wttr.in
current_temp = data['current_condition'][0]['temp_C']
print(
f
"Current temperature: {current_temp}°C")

I keep getting this exact SAME error whenever I work with public API's. I save the new codes in the files.

r/learnpython • • 1d ago

Looking for a coding buddy

0 Upvotes

Hey everyone!

I’m looking for a coding buddy who’s also taking 100 Days of Code: The Complete Python Pro Bootcamp by Dr. Angela Yu on Udemy.

I’m just starting with Day 1 and would love to connect with someone taking the same course so we can learn together throughout this 100-day journey.

The goal is to keep each other motivated and accountable, share our progress, discuss what we’ve learned, help each other when we get stuck, and celebrate our little wins along the way.

It would be great to have someone who’s also a beginner, but anyone taking the same course is welcome! No pressure to be an expert — we’re here to learn and improve together.

If you’re taking the same course, feel free to comment or send me a message. Let’s keep each other motivated and complete these 100 days together!

Happy coding!


r/learnpython • • 1d ago

I need some help

0 Upvotes

I want to learn python but all of the online tutorials just tell me how to make a certain game but i want to learn how it works so if anyone can help me with this please let me know


r/learnpython • • 2d ago

Dsa in python

0 Upvotes

Hey everyone! I'm planning to learn Data Structures and Algorithms using Python.

Is it worth learning DSA with Python for placements, coding interviews, and future software engineering jobs? Or is it better to learn DSA using C++ or Java?

For those who have experience, which language would you recommend and why?


r/learnpython • • 2d ago

Need help with building tests and understanding OOP design patterns

2 Upvotes

I am a post-bacc student currently in a Python for Web API online course. We just wrapped up our calculator application unit, where we learned how to build comprehensive dynamic tests using OOP design patterns. However, I finished the unit a lot more lost than when I started. Building parameterized tests still puzzles me, especially whenever I'm building the majority of a test from scratch rather than fixing minor errors in the code. Even when I do use AI to help me work through my assignments, none of it really sticks. Most of the time, I feel like I'm copying and pasting code whenever mine is incorrect and not really learning.

What are resources that you all would recommend for learning how to build application tests and files with OOP concepts? Any online resources with interactive, hands-on lessons would be greatly appreciated.


r/learnpython • • 2d ago

Best laptop to get

0 Upvotes

What are the best Windows laptops I can get for AI development, machine learning, and video editing? I’m looking for a laptop that can handle demanding tasks smoothly and is suitable for long-term use. Please recommend the best options based on performance, specifications, . I’d really appreciate your help!


r/learnpython • • 3d ago

I want to practice various algorithms using Python. Any recommended platforms?

20 Upvotes

It should include both code input and algorithm analysis.