Feet and inches

Tim Chase python.list at tim.thechases.com
Wed Feb 4 21:15:47 EST 2009


> Enter the height (in metres):
>  
> and convert whatever value to feet and inches. 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?

Dang...I got suckered into answering a homework problem for the 
last one.  My apologies to the professor if they eavesdrop on the 
mailing list.  However, given the demonstrated skill level of the 
programmer, if you suspect your student got the answer from my 
reply, a fairly simple tweak of the problem would separate the 
wheat from the chaff.

For this one,

1) you're using the int() function, so fractional inches coming 
from the user don't really matter anyways.

2) read up on the "%" (modulo) operator, or check out the 
divmod() function in Python.

-tkc






More information about the Python-list mailing list