I'm building simple "guess number" game in python based on book "Python Programming for the Absolute Beginner: chapter 3". I can't figure out how to make this while loop
part accept only whole numbers in input
:
# Setting initial values
computer = random.randint(1, 100)
guess = input("Take a guess: ")
while guess != int or guess != float:
guess = input("Use whole numbers: ")
tries = 1
The effect should be that after user types float or string program prints "Use only whole numbers".
After user types whole number it takes him out of the loop to the game:
# Guessing loop
while guess != computer:
if guess < computer:
print("You're bidding to low")
else:
print("You're bidding to high")
guess = int(input("Take a guess: "))
tries += 1
I tried also, but it doesn't work either:
computer = random.randint(1, 100)
guess = int(input("Take a guess: "))
while guess != int or guess != float:
guess = input("Use whole numbers: ")
if guess == int:
break
tries = 1