Created
May 9, 2018 14:55
-
-
Save spheppner/0b07928cc96ad340b7960b481986c50b to your computer and use it in GitHub Desktop.
Improved calculator (Open-Source, Python3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not sure it works correctly!