-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
66 lines (50 loc) · 1.63 KB
/
main.py
File metadata and controls
66 lines (50 loc) · 1.63 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
61
62
63
64
65
# author aesha98
# Day 10: Calculator Program
from art import logo
import os
def clear():
os.system('clear')
def subtract(first_num, second_num):
total = first_num - second_num
print(f"{first_num} - {second_num} : {total}")
def multiply(first_num, second_num):
total = first_num * second_num
print(f"{first_num} * {second_num} : {total}")
def add(first_num, second_num):
total = first_num + second_num
print(f"{first_num} + {second_num} : {total}")
def divide(first_num, second_num):
total = first_num / second_num
print(f"{first_num} / {second_num} : {total}")
def input_operation():
operation = "+\n-\n*\n/\n"
print(operation)
opr = input("Pick an operation: ")
return opr
def choose_operation(opr, first_num, second_num):
if opr == '+':
add(first_num, second_num)
elif opr == '-':
subtract(first_num, second_num)
elif opr == '*':
multiply(first_num, second_num)
elif opr == '/':
divide(first_num, second_num)
calculator_end = False
while not calculator_end:
# print logo
print(logo)
first_num = input("what's the first number?: ")
opr = input_operation()
second_num = input("what's the second number?: ")
# calculate input numbers
choose_operation(opr, first_num=first_num, second_num=second_num)
other = input(f"Type 'y' to continue with calculating with {second_num}, or type 'n' to start a new calculation: ").lower()
# check condition
if other == 'y':
opr = input_operation()
second_num = input("what's the second number?: ")
choose_operation(opr=opr)
other = input(f"Type 'y' to continue with calculating with {second_num}, or type 'n' to start a new calculation: ").lower()
elif other == 'n':
clear()