有人可以看看我的循环吗?

时间:2016-08-26 17:22:50

标签: python-3.x

伙计我不知道我的循环有什么问题,但是我继续收到错误,我的最后一行没有正确缩进,我已经多次尝试缩进但是继续收到错误。

while itemsneeded>=1:
    if (items[0]) == 86947367 :
        with open("read_it.txt") as text_file:
            try:
                price = int(text_file.readlines()[2])
            except ValueError:
                print("error")
            else:
                new_price = int(price * (items2[0]))
                print("£",new_price)

    elif (items[0]) == 78364721 :
        with open("read_it.txt") as text_file:
            try:
                price = int(text_file.readlines()[6])
            except ValueError:
                print("error")
            else:
                new_price = int(price * (items2[0]))
                print("£",new_price)

    elif (items[0]) == 35619833 :
        with open("read_it.txt") as text_file:
            try:
                price = int(text_file.readlines()[10])
            except ValueError:
                print("error")
            else:
                new_price = int(price * (items2[0]))
                print("£",new_price)

    elif (items[0]) == 84716491  :
        with open("read_it.txt") as text_file:
            try:
                price = int(text_file.readlines()[14])
            except ValueError:
                print("error")
            else:
                new_price = int(price * (items2[0]))
                print("£",new_price)

    elif (items[0]) == 46389121  :
        with open("read_it.txt") as text_file:
            try:
                price = int(text_file.readlines()[18])
            except ValueError:
                print("error")
            else:
                new_price = int(price * (items2[0]))
                print("£",new_price)
else:
    continue

如果itemsneeded不等于1或更多,我希望我的代码能够继续。

1 个答案:

答案 0 :(得分:2)

问题是continue在您的上一个else条款中。它不是必需的,因为没有继承的迭代器。一旦你的程序离开while循环,它就会继续前进。

删除最后两行。

else:
    continue
相关问题