dimanche 25 avril 2021

I build a calculator and I want to give error if they didn't type any number

Code works pretty well if you enter an actual number and operator and it actually gives u an error code if you enter an invalid operator but I want to give same error code with numbers but I dont know how I use python 3.9 help plz

num1 = float(input('Enter First Number:'))
op = input('Enter operator:')
num2 = float(input('Enter Second Number:'))

if op == '+':
    print(num1 + num2)
elif op == '-':
    print(num1 - num2)
elif op == '*':
    print(num1 * num2)
elif op == '/':
    print(num1 / num2)
else:
    print('enter an operator plz')

Aucun commentaire:

Enregistrer un commentaire