繁体   English   中英

我的代码脱离了我的for循环

[英]My code is breaking out of my for loop

所以我一直在这段代码上做一些工作,只是为了测试我的能力,而我遇到了一堵砖墙。 由于某种原因,我的代码脱离了我的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

您的错误是嵌套的for循环的结果,因为您在两者中都使用了变量i。 这会导致错误,因为您在第二个for循环中的第一个for循环中更改了变量i的值。 例如,在第二个for循环中用j重命名变量。

谢谢大家的帮助! 就我而言,这是一个愚蠢的错误。 我在学校计算机上使用3.4.4,在家里使用3.5.1。 无论如何,这一切都奏效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM