-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend_calculator.py
93 lines (80 loc) · 2.8 KB
/
backend_calculator.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#Use this calculator for basic math operations
print("|:WELCOME:|")
print("\nBackend Calculator\n")
name=input("Name: ")
print("\nOptions ->\n")
option={1:"1.Add.",2:"2.Substract.",
3:"3.Multiply.",4:"4.Divide."}
for value in option:
print(option[value])
option=int(input(f"\nHello, {name}. Choose the operation you will do: "))
num=int(input("\nHow many numbers you will choose?: "))
#Operation with 2 numbers
if num == 2:
if option >= 1 or option <= 4:
print("\nPick your numbers:")
else:
print("\nCan't do any operation.")
num1=float(input("->"))
num2=float(input("->"))
if option == 1:
result=num1+num2
print(f"\nYour result -> {num1} + {num2} = {result:.2f}")
elif option == 2:
result=num1-num2
print(f"\nYour result -> {num1} - {num2} = {result:.2f}")
elif option == 3:
result=num1*num2
print(f"\nYour result -> {num1} x {num2} = {result:.2f}")
elif option == 4:
result=num1/num2
print(f"\nYour result -> {num1} / {num2} = {result:.2f}")
#Operation with 3 numbers
elif num == 3:
if option >= 1 or option <= 4:
print("\nPick your numbers:")
else:
print("\nCan't do any operation.")
num1=float(input("->"))
num2=float(input("->"))
num3=float(input("->"))
if option == 1:
result=num1+num2+num3
print(f"\nYour result -> {num1} + {num2} + {num3} = {result:.2f}")
elif option == 2:
result=num1-num2-num3
print(f"\nYour result -> {num1} - {num2} - {num3} = {result:.2f}")
elif option == 3:
result=num1*num2*num3
print(f"\nYour result -> {num1} x {num2} x {num3} = {result:.2f}")
elif option == 4:
result=num1/num2/num3
print(f"\nYour result -> {num1} / {num2} / {num3} = {result:.2f}")
#Operation with 4 numbers
elif num == 4:
if option >= 1 or option <= 4:
print("\nPick your numbers:")
else:
print("\nCan't do any operation.")
num1=float(input("->"))
num2=float(input("->"))
num3=float(input("->"))
num4=float(input("->"))
if option == 1:
result=num1+num2+num3+num4
print(f"\nYour result -> {num1} + {num2} + {num3} + {num4} = {result:.2f}")
elif option == 2:
result=num1-num2-num3-num4
print(f"\nYour result -> {num1} - {num2} - {num3} - {num4} = {result:.2f}")
elif option == 3:
result=num1*num2*num3*num4
print(f"\nYour result -> {num1} x {num2} x {num3} x {num4} = {result:.2f}")
elif option == 4:
result=num1/num2/num3/num4
print(f"\nYour result -> {num1} / {num2} / {num3} / {num4} = {result:.2f}")
#Non-valid operation
else:
print("\nCan't do any operation.")
print(f"\nThat was it all for now, {name}.")
print("\nHope to see you soon.")
print("\nGoodbye!")