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或更多,我希望我的代码能够继续。
答案 0 :(得分:2)
问题是continue
在您的上一个else
条款中。它不是必需的,因为没有继承的迭代器。一旦你的程序离开while
循环,它就会继续前进。
删除最后两行。
else:
continue