This is my first ever project I've coded in Python so I'm sorry if it's a little novice. I'm just looking for beginner feedback on what I could improve next time.
There is one issue with this calculator: let's say I add 1 and 2, I expect to get 3
, instead it returns 3.0
, but I'm guessing that's because I'm casting to a float.
The reason I'm casting to a float is to accept decimals in the equation. It would be nicer if it displayed the whole number without the .0
while True:
calculation = input("Calculation: ")
if (calculation.__contains__("+")):
print(float(calculation.split('+')[0]) + float(calculation.split('+')[1]))
elif (calculation.__contains__("-")):
print(float(calculation.split('-')[0]) - float(calculation.split('-')[1]))
elif (calculation.__contains__("*")):
print(float(calculation.split('*')[0]) * float(calculation.split('*')[1]))
elif (calculation.__contains__("/")):
print(float(calculation.split('/')[0]) / float(calculation.split('/')[1]))