Untitled
unknown
plain_text
2 years ago
1.6 kB
14
Indexable
# Beginning prompt that allows user to select calculation options in order to get an answer.
# While True creates a loop because everything is indented under it.
while True:
print("Hello, this is a simple calculator. Choose an option to get started!")
print("1 for addition")
print("2 for subtraction")
print("3 for division")
print("4 for multiplication")
choose = input("Choose an operation: ")
choose = int(choose)
if choose == 1:
print("You have chosen addition!")
x = input("Value x: ")
y = input("Value y: ")
answer = (float(x) + float(y))
print("Your answer is: " + str(answer))
elif choose == 2:
print("You have chosen subtraction!")
x = input("Value x: ")
y = input("Value y: ")
answer = (float(x) - float(y))
print("Your answer is: " + str(answer))
elif choose == 3:
print("You have chosen division!")
x = input("Value x: ")
y = input("Value y: ")
answer = (float(x) / float(y))
print("Your answer is: " + str(answer))
elif choose == 4:
print("You have chosen multiplication!")
x = input("Value x: ")
y = input("Value y: ")
answer = (float(x) * float(y))
print("Your answer is: " + str(answer))
# This gives user the choice to do another calculation
# Remember that for word choices you need to add quotation marks otherwise they won't work.
again = input("Would you like another calculation?(yes/no) ")
if again == str("no"): breakEditor is loading...