vendredi 24 juillet 2020

Why is this calculator just running my else statement when i enter an operator?

whenever i run this and enter an operator i get my else statement error Error: Unknown operator

# Scientific calculator

Standard_Scientific: str = input("would you like to use a standard or a Scientific calculator? ")

if Standard_Scientific == 'standard'.lower():
    num1 = int(input('Enter your first number:  '))
    num2 = int(input('Enter your second number: '))
    op = (input('Enter the operator you would like to use: '))

    if op == '+ ':
        print(f'{num1} {op} {num2} = {num1 + num2}')
    elif op == '- ':
        print(f'{num1} {op} {num2} = {num1 - num2}')
    elif op == '* ':
        print(f'{num1} {op} {num2} = {num1 * num2}')
    elif op == '/ ':
        print(f'{num1} {op} {num2} = {num1 / num2}')
    else:
        print('Error: Unknown operator')

elif Standard_Scientific == 'Scientific'.lower():
    print("Coming soon!")

Aucun commentaire:

Enregistrer un commentaire