-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
69 lines (56 loc) · 2.06 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
69
from calculator import division, multiplication, sum, subtracion
from textwrap import dedent
if __name__ == "__main__":
number1: float = 0.0
number2: float = 0.0
# option_selected = 1
while True:
#A forma com que eu estava seguindo...
print("""
----------MENU----------
options:
1 - Sum
2 - subtraction
3 - division
4 - multiplication
0 - Exit
""")
#Utilizando o dedent e mantendo a indentação do código
print(dedent("""
----------MENU----------
options:
1 - Sum
2 - subtraction
3 - division
4 - multiplication
0 - Exit
"""
))
while True:
try:
option_selected = int(input('Select an option: '))
if option_selected <= 0 or option_selected > 4:
break
number1 = float(input('\nInsert the first number: '))
number2 = float(input('Insert the second number: '))
break
except:
print("Insert only numeric")
if option_selected <= 0 or option_selected > 4:
exit(0)
elif option_selected == 1:
print('\n----------SUM----------')
result = sum(number1, number2)
print(f'{number1} + {number2} = {result: .2f}')
elif option_selected == 2:
print('\n----------Subtraction----------')
result = subtracion(number1, number2)
print(f'{number1} - {number2} = {result: .2f}')
elif option_selected == 3:
print('\n----------Division----------')
result = division(number1, number2)
print(f'{number1} / {number2} = {result: .2f}')
elif option_selected == 4:
print('\n----------Multiplication----------')
result = multiplication(number1, number2)
print(f'{number1} * {number2} = {result: .2f}')