简体   繁体   中英

Why does the code always say 'The Number is Smaller"?

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()

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM