Guess the number v2
unknown
python
18 days ago
1.3 kB
6
Indexable
Never
import random def generate_random_number(): random_number = random.randint(1, 100) return random_number def guess_number_game(random_number): counter = 0 while True: number_guess = input("Guess the number:") counter += 1 if number_guess.isdigit(): number_guess = int(number_guess) if number_guess > random_number and number_guess > 0 and number_guess < 100: print(f"The number is too high! You have {10 - counter} attempts left.") elif number_guess < random_number and number_guess > 0 and number_guess < 100: print(f"The number is too low! You have {10 - counter} attempts left.") elif number_guess == random_number: print(f"Congratulations!") break elif number_guess < 1 or number_guess > 100 or type(string): print("Invalid input! Try again with a number between 1 and 100.") counter -= 1 if counter == 10: print('Game Over') break else: print("Invalid input! Try again with a number between 1 and 100.") counter -= 1 if __name__ == "__main__": random_number = generate_random_number() guess_number_game(random_number)
Leave a Comment