Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Ask for an age until it is a whole number from to . The user types -5, 200, abc and 14. What does the program say each time, and what is the age at the end?
Two tests: the conversion, and then the range.
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.
Plan. The loop asks. If the conversion fails, say Please type a whole number. If it works but the number is out of range, say that an age is from 0 to 120. Otherwise break.
-5: a number, but below 0.200: a number, but above 120.abc: not a number.14: good.Answer: the age at the end is .
Log in to join the discussion.
Loading…