+ 1
What's float for
print(float(input("Enter a number: ")) + float(input("Enter another number: "))) why does it use float?
3 Réponses
+ 1
It's also useful for doing something with the user input after like:
Calculating taxes. Without float, input would make price equal to a string which would result in an error with you try to multiply it with a floating point number like 1.07
price = float(input("Enter price of product:"))
tax = 1.07
total = price * tax
print(total)
0
thank you
0
float is a type like integer or string, you can also change it if you want with another type