{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

in class prog 3 (getWeight)

in class prog 3 (getWeight) -...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
# Guess my weight program # # Gets functions to check whether a conversion is legal # These functions come from the file conversionCheck.py # You need to have that file in the same folder as this one # (or have them both on the Desktop). # This next line tells Python to go look in that file for # new functions. import conversionCheck as cc i print "Enter your height" p # gotGoodInput is a state variable. It will become # True when we get a number that can be converted to an integer gotGoodInput = False print "gotGoodInput",gotGoodInput p # When gotGoodInput is False, not gotGoodInput is True while not gotGoodInput: reply = raw_input("Feet: ") # cc.couldBeInt will produce the value True only when # the string reply can be converted to an integer. if cc.couldBeInt(reply): gotGoodInput = True else: print "not valid input"
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: print "gotGoodInput",gotGoodInput # Now it is safe to do the conversion; the program will not # crash because the conversion fails. feet = int(reply) f gotGoodInput = False print "gotGoodInput",gotGoodInput while not gotGoodInput: reply = raw_input("Inches: ") if cc.couldBeInt(reply): gotGoodInput = True else: print "not valid input" print "gotGoodInput",gotGoodInput inches = int(reply) i # Total height in inches inches = (feet*12) + inches i # Figure out weight assuming Body Mass Index is 24 weight = (24.0 * inches * inches)/703 w # Notice that the weird string in front of weight, connected to it by # the % operator, formats it to print out with one decimal place. print "I guess your weight is","%.1f"%weight p raw_input("Press enter to exit.")...
View Full Document

{[ snackBarMessage ]}