Last answered:

17 Jul 2023

Posted on:

16 Jul 2023

0

What is wrong with my code (Q5)

What is wrong with my code (Q5)

number_1 = int(input('Please enter first number between 1 and 20: \n-'))
number_2 = int(input('Please enter second number between 1 and 20: \n-'))

if number_1 or number_2 > 20:
    print('Keep the number between 1 and 20')
elif 20 > number_1 and number_2 > 15:
    print(number_1 * number_2)
elif 20 > number_1 or number_2 > 15:
    print(number_1 + number_2)
else:
    print("0")

1 answers ( 0 marked as helpful)
Instructor
Posted on:

17 Jul 2023

0

Hi Ahmed!

Thanks for reaching out!

To compare both number_1 and number_2 individually against 20, you need to specify the condition for each variable separately:

if number_1 > 20 or number_2 > 20:

This way, the code will correctly check if either number_1 or number_2 exceeds 20.

Hope this helps.

Best,

Ivan

Submit an answer