-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.py
More file actions
49 lines (42 loc) · 1.22 KB
/
calculator.py
File metadata and controls
49 lines (42 loc) · 1.22 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
#help_screen
#Displays information about how the program works
# Accepts no parameters
# Returns nothing
def help_screen():
print("Add: Adds two numbers")
print("Subtract: Subtracts two numbers")
print("Print: Displays the result of the latest operation")
print("Help: Displays this help screen")
print("Quit: Exits the program")
# menu
# Display a menu
# Accepts no parameters
# Returns the string entered by the user.
def menu():
# Display a menu
return input("=== A)dd S)ubtract P)rint H)elp Q)uit ===")
# main
# Runs a command loop that allows users to
# perform simple arithmetic.
def main():
result = 0.0
done = False; # Initially not done
while not done:
choice = menu() # Get User choice
if choice == "A" or choice == "a": # Addition
arg1 = float(input("Enter arg 1:"))
arg2 = float(input("Enter arg 2:"))
result = arg1 + arg2
print(result)
elif choice == "S" or choice == "s": # Subtraction
arg1 = float(input("Enter arg 1:"))
arg2 = float(input("Enter arg 2:"))
result = arg1 - arg2
print(result)
elif choice == "P" or choice == "p": #Print
print(result)
elif choice == "H" or choice == "h": #Help
help_screen()
elif choice == "Q" or choice == "q":#Quit
done = True
main()