Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #calculator using main math functions, float & integer capable, divide by zero check and working out shown.
- #integer functions
- def addi():
- num1=int(input("enter first number"))
- num2=int(input("enter first number"))
- ans = (num1) + (num2)
- print(num1, "Plus", num2, "=", ans)
- def subtracti():
- num1=int(input("enter first number"))
- num2=int(input("enter first number"))
- ans = (num1) - (num2)
- print(num1, "Minus", num2, "=", ans)
- def dividei():
- num1=int(input("enter first number"))
- num2=int(input("enter first number"))
- if num2 == 0:
- print("Math Error")
- else:
- ans = (num1) / (num2)
- print(num1, "Divided by", num2, "=", ans)
- def multiplyi():
- num1=int(input("enter first number"))
- num2=int(input("enter first number"))
- ans = (num1) * (num2)
- print(num1, "Multiplied by", num2, "=", ans)
- #floating functions
- def addf():
- num1=float(input("enter first number"))
- num2=float(input("enter first number"))
- ans = (num1) + (num2)
- print(num1, "Plus", num2, "=", ans)
- def subtractf():
- num1=float(input("enter first number"))
- num2=float(input("enter first number"))
- ans = (num1) - (num2)
- print(num1, "Minus", num2, "=", ans)
- def dividef():
- num1=float(input("enter first number"))
- num2=float(input("enter first number"))
- if num2 == 0:
- print("Math Error")
- else:
- ans = (num1) / (num2)
- print(num1, "Divided by", num2, "=", ans)
- def multiplyf():
- num1=float(input("enter first number"))
- num2=float(input("enter first number"))
- ans = (num1) * (num2)
- print(num1, "Multiplied by", num2, "=", ans)
- while True:
- print("Elenas Calculator v1.0")
- choice=input("""ai = add integer
- af = add float
- si = subtract integer
- sf = subtract float
- di = divide integer
- df = divide float
- mi = multiply integer
- mf = multiply float""")
- if choice =="ai":
- addi()
- if choice == "af":
- addf()
- if choice == "si":
- subtracti()
- if choice == "sf":
- subtractf()
- if choice == "di":
- dividei()
- if choice == "df":
- dividef()
- if choice == "mi":
- multiplyi()
- if choice == "mf":
- multiplyf()
- else:
- print("Wrong selection!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement