Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Which function (int or float) would you use to read each value? (a) the number of students in a class, (b) the price of a pen, (c) a temperature such as . Why does int("3.5") fail?
int() is for whole numbers. float() is for numbers that may have a decimal point.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
int. A number of students is a whole number.float. A price can have a decimal point.float. A temperature can have a decimal point.int("3.5") fails, because int() needs text that looks like a whole number. To change "3.5" into 3, convert in two steps: int(float("3.5")).
Answer: int, float, float.
Log in to join the discussion.
Loading…