The code below shows error if a decimal (eg. 49.9) is sent to next
variable. Can you please tell me why? Why does int()
converts it into an in
import random
import time
import sys
while True:
x=random.randint(1,100)
print('''Guess my number--it's from 1 to 100.''')
z=0
while True:
z=z+1
xx=int(str(sys.stdin.readline()))
if xx > x:
print("Too High!")
elif xx < x:
print("Too Low!")
elif xx==x:
print("You Win!! You used %s guesses!"%(z))
print()
break
else:
break
in this, I first string the number str()
, which converts it into an inoperable number. Then, I int()
integerize it, to make it an operable number. I just tested your problem on my IDLE GUI, and it said that 49.8 < 50.