Skip to content

Instantly share code, notes, and snippets.

@kaosine
Created June 6, 2019 19:04
Show Gist options
  • Save kaosine/4e3822fa3e32e54c06c4c811eb0d8c10 to your computer and use it in GitHub Desktop.
Save kaosine/4e3822fa3e32e54c06c4c811eb0d8c10 to your computer and use it in GitHub Desktop.
def add(a, b):
return a+b
def multiply(a, b):
return a * b
def divide(a, b):
if b != 0:
return a / b
else:
print("You can't divide by 0")
def subtract(a, b):
return a - b
def main():
# in reality I'd NEVER use 'while True' for something like this but this is
# a simple "get back into programming" project
while True:
# display menu
print("Menu:\n")
print("\tAdd")
print("\tSubtract")
print("\tMultiply")
print("\tDivide")
print("\tQuit")
# define variables
choice = input("What is your choice: ")
results = 0
# process choice
if choice.lower() == "quit" or choice.lower() == "q":
break
elif choice == "add" or choice == "a":
results = add(int(input("First Number: ")),
int(input("Second Number: ")))
elif choice == "subtract" or choice == "s":
results = subtract(int(input("First Number: ")),
int(input("Second Number: ")))
elif choice == "multiply" or choice == "m":
results = multiply(int(input("First Number: ")),
int(input("Second Number: ")))
elif choice == "divide" or choice == "d":
results = divide(int(input("First Number: ")),
int(input("Second Number: ")))
print("Results are: " + str(results))
print("Goodbye")
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment