I just started coding and tried to make a type of a calculator that i could come up with by myself. Today I realized that for example when calculating 2.3 - 3 the result is -0.7000000000000002 so I am not looking for advice in how to make my code better tbh but to learn just why it is not making the calculations correctly. I know this code is bad but here it is:
num_1 = input("Enter a number: ")
math_problem_type = input("what kind of a math problem? Enter +, -, * or / : ")
num_2 = input("Enter another number: ")
def addition(num_1, num_2):
return float(num_1) + float(num_2)
def difference(num_1, num_2):
return float(num_1) - float(num_2)
def product(num_1, num_2):
return float(num_1) * float(num_2)
def quotient(num_1, num_2):
return float(num_1) / float(num_2)
if math_problem_type == "+":
print(addition(num_1, num_2))
elif math_problem_type == "-":
print(difference(num_1, num_2))
elif math_problem_type == "*":
print(product(num_1, num_2))
elif math_problem_type == "/":
print(quotient(num_1, num_2))
else:
print("you done fucked up bruv")