Why's the code not breaking? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why's the code not breaking?

I'm new to python, I've been working on a guessing game where while loop should break after the user input the same number as the random number displayed. But it's not stopping and I don't know what I'm doing wrong. Please help https://code.sololearn.com/co0XtNHuAi8h/?ref=app

26th Jan 2020, 8:14 AM
Kamila Sokołowska
Kamila Sokołowska - avatar
5 Answers
+ 7
Because the input is a string, and the number generated by random.randint is an integer. You should use int(input()) instead of input() Like this: user_number = int(input("Please enter in a number beetween 1 and 3: "))
26th Jan 2020, 8:49 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 4
You didn't convert the input to int. What user_number holds is a string.
26th Jan 2020, 8:47 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 1
Thanks guys, it worked! :D
26th Jan 2020, 8:50 AM
Kamila Sokołowska
Kamila Sokołowska - avatar
0
one of your "<" should be ">"
26th Jan 2020, 9:02 PM
Kristina Hayes
0
Hi, first of all make sure that line 5 of your code will give you an integer (user_number must be an integer) Second you can use if, elif instead of consecutive if statements Then you have to update variable begin to reach to 5 (begin+=1)
27th Jan 2020, 5:56 AM
Elis Sala
Elis Sala - avatar