I am attempting to learn Python, to add to my collection of languages and to get at least one programming language under my belt.
So far I've only done the basics, and to test what I've learnt I made an extremelly simple calculator:
#PyCalc Version 1.0
Loop = 0
print("-------------------------------------")
print("Welcome to the PyCalc Calculator V1.0")
print("-------------------------------------")
def Menu():
print("\n\n1 - Addition\t\t (+)")
print("2 - Subtraction\t\t (-)")
print("3 - Division\t\t (/)")
print("4 - Multiplication\t (*)")
print("5 - Exit")
return input("\n\nPlease make your selection: ")
def Addition(Val1, Val2):
print("\n\n\t", Val1, " + ", Val2, " = ", Val1 + Val2)
def Subtraction(Val1, Val2):
print("\n\n\t", Val1, " - ", Val2, " = ", Val1 - Val2)
def Division(Val1, Val2):
print("\n\n\t", Val1, " / ", Val2, " = ", Val1 / Val2)
def Multiplication(Val1, Val2):
print("\n\n\t", Val1, " * ", Val2, " = ", Val1 * Val2)
while Loop == 0:
Selection = Menu()
if Selection == "1":
Addition(int(input("\n\nX: ")), int(input("Y: ")))
elif Selection == "2":
Subtraction(int(input("\n\nX: ")), int(input("Y: ")))
elif Selection == "3":
Division(int(input("\n\nX: ")), int(input("Y: ")))
elif Selection == "4":
Multiplication(int(input("\n\nX: ")), int(input("Y: ")))
elif Selection == "5":
print("\n\nThank you for using the PyCalc Calculator V1.0")
Loop = 1
else:
print("\n\nInvalid Selection")
The code works, but I don't know if it is the most efficient, or if I've done it in the best way?
Can you see any issues and is there anything I can do to improve it?
Thank you