+ 3
Guessing number - use input in a while loop
Hi guys, I am trying to write a programm, that I have to guess a number from 1 to 9 again and again until I guess the correct number. But the problem is that the programm can only run 1 time then it come to the error with the input. Can you guys help me please :( import random a=random.randint(1,9) while True: b=str(input()) if b==a: print("Gratulation, you have guessed correctly") break else: print("Whoop, false number. Guess again:") https://code.sololearn.com/cs47pTc8CJ20/?ref=app
4 Respuestas
+ 4
Run the code in any IDE.
Solo learn code playground is not that useful when it comes to multiple input at regular interval.
+ 4
Hieu Le Chi
Also, you are trying to compare a string against an integer, so the loop will never break.
Try this:
import random
a=random.randint(1,9)
print(a)
while True:
b= int(input())
if b==a:
print("Gratulation, you have guessed correctly")
break
else:
print("Whoop, false number. Guess again:")
+ 3
In Sololearn, you must enter all your numbers prior to running the code, which is why you are getting the EOF error.
EOF: End Of File.
+ 3
Thank you guys 😊