r/learnpython • • 13h ago

Function without argument

2 Upvotes

Ive got a function that takes a dictionary as an argument.
Now Id like to program it so when the function is called without any argument, instead of an error message it prints something custom (a dictionary for example).

Any help is appreciated :D


r/learnpython • • 13h ago

Anyone help me with this loop? I cant break out of the outer loop?

3 Upvotes
while True:
    try:
        STickets = float(input("Please enter the amount of student tickets you would like"))
        if STickets %1 !=0:
            print("please enter a whole number!")
            continue
        elif STickets < 0:
            print("please enter a positive number!")
            continue
        else:
            print(f"You have selected {int(STickets)}")
            Answer = input("is this the correct number? Yes/No").strip().capitalize()
            while True:
                    if Answer == "No":
                        break
                    if Answer =="Yes":
                        print("Confirmed")
                        break
                    else:
                        Answer = input("Enter Yes or No: ").strip().capitalize()
                    if Answer == "Yes":
                    break

r/learnpython • • 16h ago

CS50 problom 4 Gussing game

0 Upvotes

this is what im trying to do https://cs50.harvard.edu/python/psets/4/game/

this my code

import random


while True:
    try:
        level = int(input("Level:"))
        if level >= 0:
            False
        number = random.randint(1, level)
        output = number
        if output < number:
            print("Too small!")
        elif output > number:
            print("Too large!")
        elif output == number:
            print("Just right!")
        
        print("Guess:", number)
    except ValueError:
        pass

when I start and give a number it give ether it stopes it "Just right!" or print both "Just right!" and Guess: so how do I make it don't do that and do what it suppose to do in the problem


r/learnpython • • 26m ago

Complete Python Roadmap for AI/ML, LLMs, NLP, RL and Robotics

3 Upvotes

Hi everyone,

I want to master Python and build a strong programming foundation for a career in AI/ML, LLMs, NLP, Reinforcement Learning, Computer Vision and Robotics.

I'd like advice on:

  1. Which Python concepts should I master from beginner to advanced?
  2. How deeply should I learn OOP, DSA, decorators, generators, multithreading and asynchronous programming?
  3. Which libraries should I prioritize: NumPy, Pandas, SciPy, Scikit-learn, PyTorch, TensorFlow and Hugging Face?
  4. What Python skills are essential for implementing ML/DL algorithms and research papers?
  5. How much Python is required for LLM development, fine-tuning and Reinforcement Learning?
  6. Which projects should I build to develop strong practical and research-oriented skills?

I'd appreciate a structured learning roadmap and recommendations for high-quality resources.

Thanks in advance!


r/learnpython • • 18h ago

Roadmap and book recommendations for advanced Python, Data Structures, and AI?

5 Upvotes

Hi everyone,

I am looking to build a strong foundation in Python with the long-term goal of getting into Machine Learning and AI.

Right now, I want to focus on three main areas:

  1. Advanced Python concepts (writing clean, efficient, and Pythonic code)
  2. Data Structures and Algorithms (DSA) in Python
  3. Transitioning from core Python to AI/ML libraries

Could you recommend a good learning roadmap, along with the best books or free resources to start with?

Thanks in advance for your help!


r/learnpython • • 15h ago

Variability in langdetect output

3 Upvotes

Hi all,
I’m using Python to filter out rows that contains non-English text from a noisy 10,000-row Excel dataset, and the final count varies slightly between runs (for example, keeping 7,522 vs. 7,508 cells—a difference of less than 0.001% of total cells). Is that normal for noisy data, and is that level of variance acceptable for research?

Thanks all!


r/learnpython • • 1h ago

B.Pharm student looking for help with a CNN-based project in Pharmacognosy!

2 Upvotes

Hi everyone!

I'm a final-year B.Pharm student working on my final-year project under Pharmacognosy, and I've decided to explore using Convolutional Neural Networks (CNNs) to detect adulterants in powdered crude drugs through microscopic images.

The idea is to train an image classification model that can distinguish genuine crude drugs from adulterated samples, potentially making herbal drug quality control more efficient.

Here's the catch: I'm a complete beginner when it comes to coding and machine learning!

I've tried a small experiment on Google Colab (black pepper vs. papaya seeds), but I have a LOT to learn.

I'm looking for help from:

  • IT/CS students or professionals familiar with Python, CNNs and image classification.
  • Anyone experienced with machine learning, microscopy or image datasets.
  • Pharmacy/Pharmacognosy researchers who could offer guidance on the scientific side.

I'm willing to put in the work and learn. I'm not expecting anyone to do the project for me; even a little guidance, useful resources, research papers or suggestions would mean a lot.

I have around 7 months to work on this, and I'd love to connect with anyone who might be interested in helping me navigate this journey.

Any help is genuinely appreciated. Thank you! :)