0
def get_guess_number():
    return input('Enter you guess: ')


if __name__ == '__main__':
    print('Welcome to the guess game!')
    correct_number = input('First person enter a number: ')
    for i in range(10):
        print('\n')
    guess_number = get_guess_number()
    while guess_number != correct_number:
        if correct_number > guess_number:
            print('The number is higher')
            # print(correct_number)
            # print(guess_number)
        elif correct_number < guess_number:
            print('The number is lower')
            # print(correct_number)
            # print(guess_number)
        guess_number = get_guess_number()

    if guess_number == correct_number:
        print('you are correct!!!')

when using 100 for correct number and 99 for guess number, it prints 'The number is lower'. I am confused by this because 100 > 99 and it should print 'The number is higher'. Could someone tell me why this is happening?

Dave
  • 1
  • Your numbers are actually strings, so they get compared lexicographically (like they were words being sorted alphabetically). `"100" < "99"` because `"1"` comes before `"9"` in ASCII. If you wrap them in `int()` they'll get treated like numbers and compared according to numeric value. – Samwise Mar 31 '22 at 23:11
  • You're comparing strings, not numbers. Check out the linked duplicate for a solution. BTW, welcome to Stack Overflow! Check out the [tour], and [ask] if you want tips. – wjandrea Mar 31 '22 at 23:11

0 Answers0