#574 · Python Basics · Beginner · 35 XP · about 5 min
A web form sends every answer as text, so an age arrives as '14' and a price as '12.50'. Write tidy_number(text) that turns the text into a number:
int: '14' gives 14, and '4.0' gives 4 too.float: '12.50' gives 12.5.The text may have spaces around it. The tests check the type of the answer as well as its value.
tidy_number('14') # returns 14 tidy_number('12.50') # returns 12.5 tidy_number('4.0') # returns 4 tidy_number('-3') # returns -3
text always holds an ordinary number, such as '7', '-2.5' or ' 0.25 '.
First solves only, ranked by stars and then time.