Tommy tried this code, but it couldn't run properly --- only allow one attempt and couldn't get the correct number. Coul
Posted: Sat May 14, 2022 7:32 pm
what are the correct codes for this problem?
Tommy tried this code, but it couldn't run properly --- only allow one attempt and couldn't get the correct number. Could you please explain to him what the problems are in this code and revise the problems --- still use while True – break statement. [10 marks] import random # Generate a random number to be guessed number = random.randint(1, 100) print ("Guess a magic number between 0 and 100") while True: guess = int(input("Enter your guess: ")) if guess == number: 3 3 print es, the number is", number) elif guess > number: print("Your guess is too high") else: print("Your guess is too low") break
Tommy tried this code, but it couldn't run properly --- only allow one attempt and couldn't get the correct number. Could you please explain to him what the problems are in this code and revise the problems --- still use while True – break statement. [10 marks] import random # Generate a random number to be guessed number = random.randint(1, 100) print ("Guess a magic number between 0 and 100") while True: guess = int(input("Enter your guess: ")) if guess == number: 3 3 print es, the number is", number) elif guess > number: print("Your guess is too high") else: print("Your guess is too low") break