DEV Community

Cover image for SIMPLE CALCULATOR (python3)
francnstein
francnstein

Posted on

SIMPLE CALCULATOR (python3)

I will continue to update this as I add more to it, a simple calculator using while loops if elif else statements. I love this example and can't wait to improve it.

You are now using SimpleCalc

print('What would you like to calculate?')

while True:
print('Options:')
print('Enter "add" to add two numbers')
print('Enter "subtract" to subtract two numbers')
print('Enter "multiply" to multiply two numbers')
print('Enter "divide" to divide two numbers')
print('Enter "quit" to end the program')
user_input = input(" ")

if user_input == "quit":
    break

elif user_input == "add":
    num1 = float(input('Enter a number: '))
    num2 = float(input('Enter another number: '))
    result = str(num1 + num2)
    print('The answer is ' + result)

elif user_input == "subtract":
    num1 = float(input('Enter a number: '))
    num2 = float(input('Enter another number: '))
    result = str(num1 - num2)
    print('The answer is ' + result)

elif user_input == "divide":
    num1 = float(input('Enter a number: '))
    num2 = float(input('Enter another number: '))
    result = str(num1 / num2)
    print('The answer is ' + result)

else:
    print('Unknown input')

solo learn
FRANCNSTEIN © 2020 | Created 𝗐𝗂𝗍𝗁 ❤

Top comments (0)