python | data types and transformations
Question:
In the code sequence below, I have no problem for "int to float", but I have a problem for "float to int".
Am I missing something? Can you help me to understand?
age = 28
weight = 55.6
# int to float
result = float(age)
print(result)
#float to int
result = int(weight)
print(weight)
I was expecting an integer result, but the decimal value keeps returning.
Answers:
Print the result instead of the weight
#float to int
result = int(weight)
print(result)
In the code sequence below, I have no problem for "int to float", but I have a problem for "float to int".
Am I missing something? Can you help me to understand?
age = 28
weight = 55.6
# int to float
result = float(age)
print(result)
#float to int
result = int(weight)
print(weight)
I was expecting an integer result, but the decimal value keeps returning.
Print the result instead of the weight
#float to int
result = int(weight)
print(result)