所以我一直在研究这个代码只是为了测试我的能力而且我遇到了一堵砖墙。出于某种原因,我的代码突破了我的for循环。如果我说我想看看有多少2个房间,它会通过第一个罚款,但他们问我有多少房间我想再次检查。如果我再次输入2,它将经历一次,然后通常继续执行其余代码。我有两个for循环设置完全相同,但由于某种原因,一个工作,另一个没有。我可能犯了一个愚蠢的错误,但我一直试图修复它多年,但没有雪茄。感谢所有帮助!
def start():
print ("Welcome to Caroline's Painting and Decorating cost estimator")
print ("Here you can see an estimate to see how much the job will cost")
print ("First though, you have to enter a few details about the job")
customerNumber = input ("Please enter your customer number ")
dateofEstimate = input ("Please enter the current date ")
def roomCalculator():
surfaceAreaCost = 0
totalPrice = 0
price = 0
count = 0
rooms = int(input("Please enter the number of rooms that require painting "))
for i in range(0, rooms):
roomName = input ("What room needs decorating? ")
wallsNumber = int(input("How many walls are in the room? "))
wallpaper = input ("Is there any wallpaper thats needs to be removed? Enter Y for yes and N for no ")
if wallpaper == "Y".lower():
surfaceAreaCost + 70
for i in range(0, wallsNumber):
count = count + 1
print ("Please enter the dimensions for wall", count)
height = int(input("How high is the wall? "))
width = int(input("How long is the wall? "))
surfaceAreaWall = height*width
wallCost = surfaceAreaWall * 15
price = surfaceAreaCost + wallCost
employeeType = input ("What employee would you like? Enter AP for apprentice or FQ for Fully-Qualified ")
if employeeType == "AP".lower():
price = price + 100
print ("You are having an apprentice do the job")
print ("The price for the", roomName, "without V.A.T is", price)
return price
elif employeeType == "FQ".lower():
price = price + 250
print ("You are having a Fully-Qualified employee to do the job")
print ("The price for the", roomName, "without V.A.T is", price)
return price
答案 0 :(得分:0)
您的错误是嵌套for循环的结果,因为您在两者中都使用变量i。这会导致错误,因为您在第一个for循环中使用第二个for循环更改变量i的值。例如,使用j在第二个for循环中重命名变量。
答案 1 :(得分:0)
谢谢大家的帮助!这对我来说是一个愚蠢的错误。我在学校的电脑上使用3.4.4,在家里使用3.5.1。无论如何,这一切都奏效了。