-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.py
More file actions
39 lines (33 loc) · 1.24 KB
/
Calculator.py
File metadata and controls
39 lines (33 loc) · 1.24 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
""" A simple calculator implemented in Python. Can perform algebraic operations. 6/30/2018 """
import AlgebraicExpression
def main():
options = {0:"Algebraic Expression", 1:"Store Variable", 2:"Print Variable"}
keep_looping = True
variables = {}
print ("Welcome to the Python 3 Calculator.")
while keep_looping:
print ("\nYour options are: ")
print_options(options)
option = input("\nEnter your choice, or q to quit: ")
if option == "0":
algebraic_expression(variables)
elif option == "1":
store_variable(variables)
elif option == "2":
print_variables(variables)
elif option == "q":
keep_looping = False
def print_options(options):
for key, value in options.items():
print ("Enter " + str(key) + " for " + value)
def algebraic_expression(variables):
AlgebraicExpression.main(variables)
def store_variable(variables):
var_name = input("\nEnter variable name: ")
var_value = float(input("Enter variable value: "))
variables[var_name] = var_value
def print_variables(variables):
for key, value in variables.items():
print (str(key) + " = " + str(value))
if __name__ == "__main__":
main()