-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalc_w_Logic.py
More file actions
61 lines (45 loc) · 1.25 KB
/
Copy pathCalc_w_Logic.py
File metadata and controls
61 lines (45 loc) · 1.25 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
'''
Calculator in Python3
Coded by Antonio Torres and Parke Lovett
Version 1.0
Revisions to continue game logic from a function to a while True loop to clean up code
'''
def addition(a,b):
return (a+b)
def subtraction(a,b):
return a-b
def multiplication(a,b):
return a*b
def division(a,b):
return a/b
def exponent(a,b):
return a**b
def game():
a = float(input("Enter a number: "))
opp = input("Enter an operator (+,-,/,*,**): ")
b = float(input("Enter another number: "))
addition_var = '+'
subtraction_var = '-'
multiplication_var = '*'
division_var = '/'
exponent_var = '**'
if opp == addition_var:
print(addition(a,b))
elif opp == subtraction_var:
print(subtraction(a,b))
elif opp == multiplication:
print(multiplication(a,b))
elif opp == division_var:
print(division(a,b))
elif opp == exponent_var:
print(exponent(a,b))
else:
print ("Incorrect Syntax")
while True:
go_again=input("would you like to go again? y/n ")
if go_again == 'y' or go_again == 'Y':
game()
break
elif go_again == 'n' or go_again == 'N':
break
game()