Skip to content Skip to sidebar Skip to footer

Newbie At Python (greater Than But Less Than; Return

cookiedict = {'banana':5, 'blueberries':5, 'jerky':5} def cookies(): return input('Which of the cookies do you want to eat?') def number(): return int(input('How many cook

Solution 1:

x >0 <=5 is short for x > 0 and 0 <= 5. Since 0 is always less than 5, the second part is always true and you end up only comparing >0.

What you want is: 0 < x <= 5, which means 0 < x and x <= 5.

Solution 2:

It is always printing because you are not comparing the number input but the number of available cookies. You need to compare the input number and print if the input number is <=5 and >0. Do This:-

whileTrue:
    if0 < number <= 5:
        cookiedict[cookies] -= number
        print ('You ate {} of the {} cookies'.format(number,cookies))
    elif number >= 6:
        print ('Game Over!!! You ate too much!!!')
        breakelse:
        print ('Incorrect Input. Try again...')

Post a Comment for "Newbie At Python (greater Than But Less Than; Return"