开发者

program works at random sometimes not [closed]

Closed. This question needs debugging details. It is not currently accepting answers.

Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.

Closed 2 hours ago.

Improve this question

i wrote this simple开发者_如何学JAVA program for a cart and list system, but when i run it, it works sometimes, and sometimes not randomly and i don't know how to fix it, it supposed to move the input item to the basket here is the code:

list1 = ["apples", "milk", "eggs", "flour", "rice", "oranges"]
basket = []

while True:
    for i in list1:
        item = str(input("Enter item name: ")).lower()
        if i == item:
            basket.append(i)
            list1.remove(i)
            print(f"{i} in the list, added to the basket({len(basket)}): {basket}")
            print(f"{len(list1)} more items to get: {list1}")
        elif i != item:
            print(f"{item} is not in the shopping list ({len(list1)})")
        elif len(list1) == 0:
            print("shopping finished")
            break

tried everything to fix it but no avail, please help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜