Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python | data types and transformations

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

>Solution :

Print the result instead of the weight

#float to int

result = int(weight)
print(result)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading