-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
46 lines (35 loc) · 1.34 KB
/
Copy pathmain.py
File metadata and controls
46 lines (35 loc) · 1.34 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
while True: # for running loop
Num1 = float(input('Enter Your First Number: ')) # ask the first number
Num2 = float(input('Enter Your Second Number: ')) # ask the second number
print("Available operators: + - * / // % **")
operator = input('Enter Your Operator: ') # ask for the operator
if operator == '+':
print(f"{Num1}+{Num2}={Num1 + Num2}")
elif operator == '-':
print(f"{Num1}-{Num2}={Num1 - Num2}")
elif operator == '*':
print(f"{Num1}*{Num2}={Num1 * Num2}")
elif operator == '/':
if Num2 == 0:
print("Division by 0 is not allowed")
else:
print(f"{Num1}/{Num2}={Num1 / Num2}")
elif operator == '%':
if Num2 == 0:
print("Division by 0 is not allowed")
else:
print(f"{Num1}%{Num2}={Num1 % Num2}")
elif operator == '**':
print(f"{Num1}**{Num2}={Num1 ** Num2}")
elif operator == '//':
if Num2 == 0:
print("Division by 0 is not allowed")
else:
print(f"{Num1}//{Num2}={Num1 // Num2}")
else:
print("Invalid operator. Please choose one of the available operators.")
x = input('Do you want to continue? (y/n): ').lower()
if x != 'y':
print("Thank you for using the calculator!")
print("Calculator closed.")
break