-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc.py
51 lines (38 loc) · 1.31 KB
/
calc.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
#T##########_______THIS IS A SAMPLE CODE TO ACT AS A CALCULATOR_______##########
#STEP 1
while True:
print('Options for calculating:')
print('Insert "add" for addition')
print('Insert "sub" for subtraction')
print('Insert "mul" for multiplication')
print('Insert "div" for division')
print('Insert "rem" for finding remainder of ')
print('Insert "dib" for number of times a number is divisible by')
print('Insert "per" for percentage')
print('Insert "quit" to stop calculator')
i = input(':')
##STEP 2
if i == 'quit':
break
elif i == 'add':
n1 = float(input('Insert number;'))
n2= float(input('Insert another number:'))
r=str(n1 + n2)
print('Answer is:_ ' + r)
elif i == 'sub':
n1 = float(input('Insert number;'))
n2= float(input('Insert another number:'))
r=str(n1 - n2)
print('Answer is:_ ' + r)
elif i == 'mul':
n1 = float(input('Insert number;'))
n2= float(input('Insert another number:'))
r=str(n1 * n2)
print('Answer is:_ ' + r)
elif i == 'div':
n1 = float(input('Insert number;'))
n2= float(input('Insert another number:'))
r=str(n1 / n2)
print('Answer is:_ ' + r)
else:
print('invalid input')