[Python] In this code, is there a way to stop printing "the current number is in the hundreds"...

Discussão em 'Python' iniciado por Stack, Fevereiro 21, 2025.

  1. Stack

    Stack Membro Participativo

    I created a number reducer game where a number is randomly generated and you reduce it until it reaches 0; no retaining numbers, or negatives. The mathematical aspect of it works. A minor problem is that the print still shows that its in the hundreds when the current number is in the tens.

    I've tried using the and function (y != certain number and using the lens function), and changing the if argument from y > ... to lens == ... (I casted it such that the number is converted from int to str).

    #Import
    import random

    #Variables
    startingrange = 1
    endingrange = 1000
    number = random.randrange(startingrange, endingrange)
    number = str(number)
    inputcount = 0
    x = 0
    lens = len(number)

    #Gameset
    print("Welcome to the number reduction game!")
    print("The simple rule is to reduce number until it REACHES ZERO.\nThis means no remaining values, and no negative values.\n")
    print(f"\nYou have a {lens} digit number.")
    while True:

    #How the number is being reduced, x increases as value is inputted, which subtracts the number
    print("Enter a number: ")
    z = input()
    number = int(number)
    z = int(z)
    x += z
    y = number - x
    print(y)
    if y <= 999:
    print("Your current number is in the hundreds")
    if y <= 99:
    print("Your current number is in the tens. Getting close!")
    if y <= 9:
    print("SINGLE DIGITS!! EXTREMELY CLOSE!! DONT BACK DOWN NOW!")
    if y == 0:
    print("CONGRATULATIONS! YOU WIN!")
    break
    if y < 0:
    print(f"You lose! you reached {y}")
    break

    Continue reading...

Compartilhe esta Página