Posted on:

04 Jun 2022

1

For Question 3, negative integer inputs are not handled correctly

In the current solution, a negative integer input will give the message 'That's not even an integer! What are you playing at?!' To handle it fully correctly, we will need a separate conditional. Something like -

my_pick = 4
guess = input('I have chosen an integer between 1 and 10 inclusive. Guess what I picked. >>> ')
if str(-int(guess)).isdigit():
    print('You picked a number out of range, duh!')
elif guess.isdigit():
    guess = int(guess)
    if guess > my_pick and guess <= 10:
        print('You have guessed a number too high.')
    elif guess < my_pick and guess >= 1:
        print('You have guessed a number too low.')
    elif guess == my_pick:
        print('You guessed the right number -',my_pick,'!!')
    else:
        print('You picked a number out of range, duh!')
else:
    print('That is not even a number you scamster!')

This will give an 'out of range' message for negative integers which would be more accurate.

0 answers ( 0 marked as helpful)

Submit an answer