I am working on a code that is supposed to use a while loop to determine if the number inputted by the user is the same as the variable secret_number = 777. the following criteria are:
will ask the user to enter an integer number;
will use a while loop;
will check whether the number entered by the user is the same as the number picked by the magician. If the number chosen by the user is different than the magician's secret number, the user should see the message "Ha ha! You're stuck in my loop!" and be prompted to enter a number again.
If the number entered by the user matches the number picked by the magician, the number should be printed to the screen, and the magician should say the following words: "Well done, muggle! You are free now."
if you also have any tips how to use the while loop that would be really helpful. Thank you!
Here is how it's done:
secret_number = 777
n = int(input("Enter an integer number: "))
if n != secret_num: # If statement to chack if the numbers match
print("Ha ha! You're stuck in my loop!")
while True:
input("Enter an integer number: ") # Loop never ends...
print("Well done, muggle! You are free now.") # If the program made it here, that means the user's number matched
Output:
Enter an integer number: 7
Ha ha! You're stuck in my loop!
Enter an integer number: 2
Enter an integer number: 2
Enter an integer number: 3
Enter an integer number: 4
Enter an integer number: 56
Enter an integer number: 789
Enter an integer number:
Enter an integer number: 8765
Enter an integer number:
...
Round 2:
Enter an integer number: 777
Well done, muggle! You are free now.
>>>