Skip to content

Instantly share code, notes, and snippets.

@KatiGithub
Created June 29, 2018 13:28
Show Gist options
  • Save KatiGithub/63b5785790f10f193e00a2a28aad2977 to your computer and use it in GitHub Desktop.
Save KatiGithub/63b5785790f10f193e00a2a28aad2977 to your computer and use it in GitHub Desktop.
This program is a simple addition and subtraction calculator and and will ask whether you want to subtract or add and after done with the first set of numbers it will ask to restart and you can either break or do it again. This loop is only two times.
answer = input("Do you want to subtract or add:")
def add_numbers():
first_number = int(input("What would be your first number to add? "))
second_number = int(input("What would be your second number to add? "))
total = first_number + second_number
print(total)
def subtract_numbers():
first_number = int(input("What would be your first number to subtract? "))
second_number = int(input("What would be your second number to subtract? "))
total = first_number - second_number
print(total)
if answer == "add":
add_numbers()
elif answer == "subtract":
subtract_numbers()
else:
print("You either pressed enter without entering or didn't type subtract nor add. TRY AGAIN!")
restart_or_not = input("Do you want to restart? If yes please specify add or subtract and if not, please type Y and enter! ")
if restart_or_not == "add":
add_numbers()
elif restart_or_not == "subtract":
subtract_numbers()
else:
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment