Feet and inches

Tim Rowe digitig at gmail.com
Wed Feb 4 21:17:08 EST 2009


2009/2/5 todpose at hotmail.com <todpose at hotmail.com>:
> I'm trying to get Python to say:
>
> Enter the height (in metres):
>
> and convert whatever value to feet and inches.

This looks like another homework assignment. You'll probably get more
help (on *any* language forum) if you admit that up front. However, at
least this time you've shown us that you've made a good first attempt,
so here are a few hints.

> I've done this part as you
> can see below, but how can I terminate the program when user inputs a height
> less than 1/2 inch?

The program already terminates when the user inputs any height. If you
want it to *keep* asking you need to wrap it in some sort of loop.
Look up "while" and "break".

> How can I also take into account all the cases that need an exception?

I think your code already takes into account all the cases that need
an exception -- you just need to handle the exceptions. Try entering
some silly values for the height (try something like "one point three"
for example) and look at the exception you get. Then look up "try" and
"catch" to see what you might do about it. You might like to think
about what should happen if a user enters a negative value, but the
present behaviour -- when fixed -- may be what you need.

-- 
Tim Rowe



More information about the Python-list mailing list