+ 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

11th Aug 2021, 10:19 AM
Hieu Le Chi
Hieu Le Chi - avatar
4 Antworten
+ 4
Run the code in any IDE. Solo learn code playground is not that useful when it comes to multiple input at regular interval.
11th Aug 2021, 10:28 AM
Nitin Tiwari
Nitin Tiwari - avatar
+ 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:")
11th Aug 2021, 10:35 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 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.
11th Aug 2021, 10:32 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 3
Thank you guys 😊
11th Aug 2021, 11:43 AM
Hieu Le Chi
Hieu Le Chi - avatar