this post was submitted on 01 May 2025
24 points (100.0% liked)

Python

7069 readers
17 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

πŸ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
πŸ’“ Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 2 years ago
MODERATORS
 

There is an issue with the program when the user correctly guesses the number. The program should end when the break statement executes in the while loop found in main(), but instead it times out.

import random


def main():
    level = get_level()
    number = generate_random_number(level)

    while True:
        guess = get_guess()

        if check_guess(number, guess) == False:
            continue
        else:
            break


def get_level():
    while True:
        level = input("Level: ")

        try:
            int(level)
        except ValueError:
            continue
        if int(level) <= 0:
            continue
        else:
            return int(level)

def generate_random_number(level):
    number = random.randint(1, level)

    return number

def get_guess():
    while True:
        guess = input("Guess: ")

        try:
            int(guess)
        except ValueError:
            continue
        if int(guess) <= 0:
            continue
        else:
            return int(guess)

def check_guess(number, guess):
    if guess > number:
        print("Too large!")

        return False
    if guess < number:
        print("Too small!")

        return False
    if guess == number:
        print("Just right!")

        return True


main()
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 2 days ago (1 children)

or not introducing another programming language into your toolchain by sticking with black, flake8, isort, and pre-commit

[–] [email protected] 1 points 1 day ago (1 children)

At the user level they're just tools, not programming languages. Python users are generally moving to ruff (and uv) because of ergonomics: It works well and really fast which makes for a smooth experience in-editor. Plus using fewer tools to achieve a similar result is generally desirable.

And for a complete newbie like someone taking a course, I think there's no "sticking with" to speak of. Might as well just skip over the tools people are migrating away from and start with the tool people are migrating to.

[–] [email protected] 1 points 21 hours ago

Can see both the pros and cons.

Looking at existing packages we actually use, it's a mixed bag. When helping other projects, have not run into the situation where had to use ruff. Do see some uptake. It's not like a light switch there will be multiple commits before the ruff configuration is right. But i'm sure the configuration is simplier than the rocket science that is: black, flake8, isort, pre-compile, tox configurations.

Overtime expect Rust to bleed into the Python toolchain. The excuse to resist this is there is not enough time in the day for Python let alone other coding languages especially low level languages like Rust and integration of those low level languages and Python. Sounds like a ton of work unless intending to write Rust modules to optimize speed of complex Python apps.