-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator_project.py
More file actions
46 lines (40 loc) · 1.55 KB
/
Copy pathcalculator_project.py
File metadata and controls
46 lines (40 loc) · 1.55 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
46
def main() -> None:
print("Welcome to the Calculator")
print("-" * 40)
while True:
try:
num1 = float(input('Enter first number: '))
print("Select Operation: +, -, *, /, **")
operation = input("Enter operation: ")
num2 = float(input('Enter second number: '))
if operation == '+':
result = num1 + num2
print(f"{num1} + {num2} = {result}")
elif operation == '-':
result = num1 - num2
print(f"{num1} - {num2} = {result}")
elif operation == '*':
result = num1 * num2
print(f"{num1} * {num2} = {result}")
elif operation == '/':
if num2 == 0:
print("Error: Division by zero")
continue
result = num1 / num2
print(f"{num1} / {num2} = {result}")
elif operation == '**':
if num2 < 0:
print("Error: Exponent cannot be negative")
continue
result = num1 ** num2
print(f"{num1} ** {num2} = {result}")
else:
print("Invalid operation")
continue_choice = input("Perform another calculation? (yes/no): ").lower()
if continue_choice not in ['yes', 'y']:
print("Thank you for using the calculator")
break
except ValueError:
print("Invalid input")
if __name__ == "__main__":
main()