Skip to content

Instantly share code, notes, and snippets.

@spheppner
Created May 9, 2018 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spheppner/0b07928cc96ad340b7960b481986c50b to your computer and use it in GitHub Desktop.
Save spheppner/0b07928cc96ad340b7960b481986c50b to your computer and use it in GitHub Desktop.
Improved calculator (Open-Source, Python3)
credits = """
Made by Simon Heppner
on 9th of May, 2018
"""
print(credits)
def addition(int1, int2):
return (int1 + int2)
def subtraction(int1, int2):
return (int1 - int2)
def division(int1, int2):
if int2 == 0:
print("Division by 0 isn't an option!")
break
return (int1 / int2)
while True:
i = input("[A]ddition, [S]ubtraction, [D]ivision or [Q]uit? > ")
if i != "":
if i == "A":
while True:
i1 = input("Please enter the first number! > ")
if i1 != "":
while True:
i2 = input("Please enter the second number! > ")
if i2 != "":
value = addition(i1, i2)
print(value)
elif i2 == "":
print("Please enter a valid number!")
continue
elif i == "":
print("Please enter a valid number!")
continue
if i == "S":
while True:
i1 = input("Please enter the first number! > ")
if i1 != "":
while True:
i2 = input("Please enter the second number! > ")
if i2 != "":
value = subtraction(i1, i2)
print(value)
elif i2 == "":
print("Please enter a valid number!")
continue
if i == "D":
while True:
i1 = input("Please enter the first number! > ")
if i1 != "":
while True:
i2 = input("Please enter the second number! > ")
if i2 != "":
value = division(i1, i2)
print(value)
elif i2 == "":
print("Please enter a valid number!")
continue
if i == "Q":
break
elif i == "":
print("Nothing is not an option!")
continue
@spheppner
Copy link
Author

Not sure it works correctly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment