mercredi 26 septembre 2018

How to get the the "Error" message printed in this situation because the "else" statement doesn't work?

Write the program that reads in input three integers a, b and c. If the integer c is equal to 1, then the program displays on output (prints) the value of a + b; if c is 2 then the program displays the value of a-b; if c is equal to 3 then the output will be the value of ab. Finally, if the value 4 is assigned to c, then the program displays the value of a^2 + ba. If c contains another value, the program displays the message "Error"

a = int(input())

b = int(input())

c = int(input())

if c == 1 :

print(a + b)

if c == 2 :

print(a - b)

if c == 3 :

print(a * b)

if c == 4 :

print(a**2 + b*a)

else :

print('Error')

Aucun commentaire:

Enregistrer un commentaire