I tried to make this easy program using random and loops. I am really bad in loops. The random number generation worked perfectly but its was not able to loop through this program. Here is the program
print("You will have to guess the number chosen by the computer.The computer will choose a number from 1 to 10")
User_Input = int(input("Make your guess: "))
if User_Input > 10:
print("Your guess is more than 10, Please choose between 1 and 10")
else:
print("The computer is choosing......")
Computer_List = ("1","2","3","4","5","6","7","8","9","10")
import random
Chosen_Number = random.choice(Computer_List)
for Calculation in Chosen_Number:
if User_Input < Chosen_Number:
print("The number you have chosen is more than the number chosen by the computer. Try again!")
elif User_Input > Chosen_Number:
print("The number you have chosen is less than the number chosen by the computer. Try again!")
elif User_Input == Chosen_Number:
print("The number chosen by you is CORRECT!")
else:
print("Some error occured try again")
break
Please don’t send a whole new and modified program as I don’t want to copy but I want to learn, just help me on what’s the error, what made this error occur and how to fix it.
Thanks for all the people who replied to this help request
To answer that question, you should run the program several times to test it with various inputs.
EDIT (March 2, 2022):
If, when you run your program, you get an error message, please post the most recent version of your code, as well as a copy of the error message.
Also check the logic of the expressions in the headers of your conditional blocks to make sure they make sense, when compared to the associated print statements. For example, does the condition here match the printed message?:
if User_Input < Chosen_Number:
print("The number you have chosen is more than the number chosen by the computer. Try again!")
Please make sure to test the program even after you are not receiving any error messages. A program may execute without an error message, but still not produce the desired result.
Make sure the break statement is in the correct conditional block. For instance, it might need to be moved to the block that executes when the computer has discovered the correct number.