0% found this document useful (0 votes)
14 views1 page

Hehe

This document is a simple calculator program that allows users to perform basic arithmetic operations: addition, subtraction, multiplication, and division. Users can input their choice of operation and two numbers, and the program will display the result. The program continues to prompt for calculations until the user decides to exit.

Uploaded by

alicool5875
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views1 page

Hehe

This document is a simple calculator program that allows users to perform basic arithmetic operations: addition, subtraction, multiplication, and division. Users can input their choice of operation and two numbers, and the program will display the result. The program continues to prompt for calculations until the user decides to exit.

Uploaded by

alicool5875
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

print("Select operation.

")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
while True:
choice = input("Enter choice(1/2/3/4): ")

if choice in ('1', '2', '3', '4'):


try:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
except ValueError:
print("Invalid input")
continue

if choice == '1':
print(num1, '+', num2, '=', (num1 + num2))
elif choice == '2':
print(num1, '-', num2, '=', (num1 - num2))
elif choice == '3':
print(num1, '*', num2, '=', (num1 * num2))
elif choice == '4':
print(num1, '/', num2, '=', (num1 / num2))

Next = input("Retry calculation? (yes/no): ")


if Next == "no":
break
else:
print("Invalid input")

You might also like