首页 > 解决方案 > 这是一个简单的python装箱单

问题描述

作为一个私人练习,我尝试编写一个小型 python 程序。我经常旅行,总是寻找相同的东西。因此我认为有一个装箱单是有意义的。

我的输入是职业、机动性、小麦和持续时间。我的输出是一个包含项目的列表。

我的文件要大得多,但这是程序的基本部分

    packinglist = []

    clothes = ["T-Shirt(s)", "Extra Shoes", "Ironed Shirts"]

    occupation = []
    while occupation != "Business" or occupation !="Private" or occupation         
    !="Outdoor":

        occupation =str(input('Whats the purpose: Business, Private, or Outdoor?\n'))
    if occupation == "Business" or occupation =="Private" or occupation =="Outdoor":
        print("Okay. Go on!\n")
        break

    while True:
    try:
        days = int(input('How many days are you travelling?\n'))
        break
    except ValueError:
        print("Wrong Entry, please type in a posive number!")

我包括了很多条件,例如:

    if days >2 and occupation=="Business":
        packinglist.append(hardware[2])     #Shaver
        packinglist.append(personals[9])    #Watch
        packinglist.append(documents[5])    #Card Wallet


    packinglist1 = list( dict.fromkeys(packinglist))

    print("---clothes---:\n")
    for clothes_id in packinglist1:
        if clothes_id in clothes:
            print(clothes_id)
        else:
            pass


    print("\n")
    print("---Summary.---\n")
    print("Your Trip is for:", occupation)
    print("Wheater condition:", wheater)
    print("Sports activites:", sport)
    print("Days of duration:", days)

在这里,我添加了包含特定旅程的单独内容的选项

    names = []
    new_object = ''
    while new_object != 'quit':
        new_object = input("You want to add something to the list?, or enter 'quit': ")
        packinglist1.append(new_object)

有很多更漂亮的编码方式,但我还做不到。因此,如果您愿意,可以给我建议如何改进该程序。

我认为拥有将旅程的“天数”考虑在内的模型会很好。此外,使用例如 Tkinter 的良好可视化看起来非常好。让我们看看会发生什么

标签: python-3.xlistpacking

解决方案


推荐阅读