-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
68 lines (46 loc) · 1.69 KB
/
main.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import math
def add(x: float, y: float):
return x + y
def subtract(x: float, y: float):
return x - y
def multiply(x: float, y: float):
return x * y
def divide(x: float, y: float):
return x / y
def mod(x: float, y:float):
return x % y
def power(x: float, y: float):
return x ** y
def factorial(x: int):
return math.factorial(x)
def main():
while True:
choice = input("Choose operation (+, -, *, /, %, ^, !): ")
if choice in '+-*/%^':
try:
operand_1 = float(input("First operand: "))
operand_2 = float(input("Second operand: "))
except ValueError:
print("Not a number.")
continue
if choice == '+':
print(f'{operand_1} + {operand_2} = {add(operand_1, operand_2)}')
elif choice == '-':
print(f'{operand_1} - {operand_2} = {subtract(operand_1, operand_2)}')
elif choice == '*':
print(f'{operand_1} * {operand_2} = {multiply(operand_1, operand_2)}')
elif choice == '/':
print(f'{operand_1} / {operand_2} = {divide(operand_1, operand_2)}')
elif choice == '%':
print(f'{operand_1} % {operand_2} = {mod(operand_1, operand_2)}')
elif choice == '^':
print(f'{operand_1} ^ {operand_2} = {power(operand_1, operand_2)}')
if choice == '!':
try:
operand_1 = int(input("Operand: "))
except ValueError:
print("Not a number.")
continue
print(f'{operand_1}! = {factorial(operand_1)}')
if __name__ == "__main__":
main()