DmS1ckwit1t
How can I loop the question untill the user selects yes? - Nevermind figured it out
Heres what I have so far:
*EDIT* Would my code still work if I changed all of the While Statments To if minus the one checking for yes?
""" Tile Cost Calculator
TileCostCalc.py
Adapating to python
August 13th, 2009
Dillon Mulroy
"""
#Sets the price of ea. tile and stores it as an integer.
tileCost = raw_input("What is the price per tile? ")
tileCost = int(tileCost)
prompt1 = "Is %d$ the correct price per tile? Y/N " %(tileCost)
#Creates a string variable for the while statments. yn.upper() will make it easier to test in a conditional statement, as will counting the length of the string.
yn = raw_input(prompt1)
yn = yn.upper()
numChars = len(yn)
#Tests if string yn is "Y" if yes it moves on into the program
while yn == ("Y"):
print "Okay, onto the next question..."
length = raw_input("In feet, what is the length of the room? ")
length = int(length)
prompt2 = "is %dft the correct price per tile? Y/N " %(length)
yn2 = raw_input(prompt2)
#Tests if string yn is "N" if false it loops back to setting variable tileCost
while yn == ("N"):
tileCost = raw_input("What is the price per tile? ")
tileCost = int(tileCost)
yn = raw_input(prompt1)
yn.upper()
numChars= len(yn)
#Test if string yn is a valid answer if false it loops back to setting variable tileCost
while yn!= ("Y" , "N"):
print "This is an invalid answer."
print
tileCost = raw_input("What is the price per tile? ")
tileCost = int(tileCost)
yn = raw_input(prompt1)
yn.upper()
numChars= len(yn)
#Tests if string yn is short enough to be a valid answer if false it loops back to setting variable tileCost
while numChars > 1 :
print "There are to many characters in your answer please retry..."
print
tileCost = raw_input("What is the price per tile? ")
tileCost = int(tileCost)
yn = raw_input(prompt1)
yn.upper()
numChars= len(yn)
This post has been edited by DmS1ckwit1t: 13 August 2009 - 08:01 PM

New Topic/Question
Reply




MultiQuote



|