I made a number guesser although I believe the logic for the else statement can be improved /u/Upper-Abroad-5868 Python Education

# python number guesser import random lowest_num = 0 highest_num = 100 answer = random.randint(lowest_num,highest_num) while True: guess = int(input("Guess the random number between 1 - 100!: ")) if guess < lowest_num or guess > highest_num: print(f"{guess} is invalid!") elif guess < answer: print(f"{guess} TOO LOW! TRY AGAIN") elif guess > answer: print(f"{guess} TOO HIGH! TRY AGAIN") elif guess == answer: print(f"{guess} is correct!") break else: print(f"{guess} is not a valid number!") 

submitted by /u/Upper-Abroad-5868
[link] [comments]

​r/learnpython # python number guesser import random lowest_num = 0 highest_num = 100 answer = random.randint(lowest_num,highest_num) while True: guess = int(input(“Guess the random number between 1 – 100!: “)) if guess < lowest_num or guess > highest_num: print(f”{guess} is invalid!”) elif guess < answer: print(f”{guess} TOO LOW! TRY AGAIN”) elif guess > answer: print(f”{guess} TOO HIGH! TRY AGAIN”) elif guess == answer: print(f”{guess} is correct!”) break else: print(f”{guess} is not a valid number!”) submitted by /u/Upper-Abroad-5868 [link] [comments] 

# python number guesser import random lowest_num = 0 highest_num = 100 answer = random.randint(lowest_num,highest_num) while True: guess = int(input("Guess the random number between 1 - 100!: ")) if guess < lowest_num or guess > highest_num: print(f"{guess} is invalid!") elif guess < answer: print(f"{guess} TOO LOW! TRY AGAIN") elif guess > answer: print(f"{guess} TOO HIGH! TRY AGAIN") elif guess == answer: print(f"{guess} is correct!") break else: print(f"{guess} is not a valid number!") 

submitted by /u/Upper-Abroad-5868
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *