-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
55 lines (49 loc) · 1.45 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
from art import logo
from replit import clear
print(logo)
def add(f_num, s_num):
return f_num + s_num
def sub(f_num, s_num):
return f_num - s_num
def mul(f_num, s_num):
return f_num * s_num
def div(f_num, s_num):
return f_num / s_num
def math_operation(f_num, operator , s_num):
if operator == "+":
result = add(f_num, s_num)
return result
if operator == "-":
result = sub(f_num, s_num)
return result
if operator == "*":
result = mul(f_num, s_num)
return result
if operator == "/":
result = div(f_num, s_num)
return result
operation = ["+", "-", "*", "/"]
is_start_new = False
is_cal_again = False
while not is_start_new:
f_num = float(input("What's your first number: "))
for operator in operation:
print(operator)
operator = input("Pick an operation: ")
s_num = float(input("What's your next number: "))
result = math_operation(f_num, operator, s_num)
print(f"{f_num} {operator} {s_num} = {result}")
while not is_cal_again:
closed = input(f"Type 'y' to continue calculating with {result}, or type 'n' to start a new calculation: ")
if closed == 'n':
is_cal_again = True
clear()
else:
clear()
for operator in operation:
print(operator)
operator = input("Pick an operation: ")
s_num = float(input("What's your next number: "))
result1 = result
result = math_operation(result, operator, s_num)
print(f"{result1} {operator} {s_num} = {result}")