forked from fenyx-it-academy/Class4-PythonModule-Week4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4- Mis Calculator.py
More file actions
60 lines (47 loc) · 1.94 KB
/
4- Mis Calculator.py
File metadata and controls
60 lines (47 loc) · 1.94 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import math
from Addition import addition
from Subtraction import subtraction
from Multiplication import multiplication
from Division import division
round_number_ceil = math.ceil
def get_number_input():
while True:
try:
number = float(input("Please enter a float ( with '.' ) number: "))
break
except ValueError:
print("Oops! That was no valid number. Try again...")
return number
def get_operator_symbol():
while True:
try:
symbol = input("Please enter a mathematical operator symbol (+,-,*,/): ")
if symbol != '+' and symbol != '-' and symbol != '*' and symbol != '/':
raise ValueError
break
except ValueError:
print("Oops! That was no valid symbol. Try again...")
return symbol
def get_y_n_answer():
while True:
try:
letter = input("Would you like to make another calculation (Y,N): ")
if letter != 'Y' and letter != 'y' and letter != 'N' and letter != 'n':
raise ValueError
break
except ValueError:
print("Oops! That was no valid symbol. Try again...")
return letter
while True:
operator_symbol = get_operator_symbol()
if operator_symbol == '+':
print("Result: " + str(round_number_ceil(addition(get_number_input(), get_number_input()))))
elif operator_symbol == '-':
print("Result: " + str(round_number_ceil(subtraction(get_number_input(), get_number_input()))))
elif operator_symbol == '*':
print("Result: " + str(round_number_ceil(multiplication(get_number_input(), get_number_input()))))
elif operator_symbol == '/':
print("Result: " + str(round_number_ceil(division(get_number_input(), get_number_input()))))
answer_letter = get_y_n_answer()
if answer_letter == 'N' or answer_letter == 'n':
break