Reputation: 35
I'm a beginner in python and today I tested out my knowledge by making a Number guessing game. Whenever I try to run it, it works fine, however it always says that the number is lower than my guess.
I can't figure out the problem, so I haven't really tried any solutions.
import random
while True:
print('Welcome! Type "Play" to play. Type "Quit" to Quit the program.')
choice = input()
if 'Play' in choice:
print('Very Well. I am thinking of a number Between 1 and Hundred. Try to Guess it!')
break
elif 'Quit' in choice:
exit()
else:
print("Sorry, That's not a valid Function.")
continue
number = random.randint(1, 100)
GuessesTaken = 0
while GuessesTaken < 13:
guess = int(input('Enter a Number: '))
GuessesTaken += 1
if guess > number:
print('The Number is bigger than that!')
continue
if guess < number:
print('The number is Smaller than that!')
continue
if guess == number:
print(f'You got it! he Number is {number}! Thanks for Playing!')
break
if GuessesTaken > 13:
print(f"Sorry, You're out of Guesses. The number was {number}" )
exit()
Upvotes: 0
Views: 72
Reputation: 81684
You mixed the signs in these if
conditions:
if guess > number:
print('The Number is bigger than that!')
continue
if guess < number:
print('The number is Smaller than that!')
continue
if guess > number
should be if guess < number
and vice-versa.
If guess
is greater than number
it means it means number
is smaller, and vice-versa.
Upvotes: 2