Repository navigation
Expand file tree
/
Copy pathcalculator.py
More file actions
46 lines (37 loc) · 1.43 KB
/
Copy pathcalculator.py
File metadata and controls
46 lines (37 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
first_digit = input("Enter the first digit: ")
second_digit = input("Enter the second digit: ")
for i in range(2):
if not first_digit.isdigit() or not second_digit.isdigit():
print("Invalid input! Please enter valid digits.")
first_digit = input("Enter the first digit: ")
second_digit = input("Enter the second digit: ")
def calculate_sum():
return int(first_digit) + int(second_digit)
def calculator_product():
print("Choose an operation:")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
choice = input("Enter choice (1/2/3/4): ")
if choice == '1':
print(f"The sum is: {calculate_sum()}")
elif choice == '2':
print(f"The difference is: {int(first_digit) - int(second_digit)}")
elif choice == '3':
print(f"The product is: {int(first_digit) * int(second_digit)}")
elif choice == '4':
if int(second_digit) != 0:
print(f"The quotient is: {int(first_digit) / int(second_digit)}")
else:
print("Error! Division by zero.")
else:
choice != '1' and choice != '2' and choice != '3' and choice != '4'
print("Invalid input! Please enter a valid choice.")
calculator_product()
yes = input("Do you want to continue? (yes/no): ").strip().lower()
if yes == 'yes':
print("Continuing the program...")
calculator_product()
else:
print("Exiting the program.")