分离列表以在新列表上仅打印一种类型的项目

时间:2019-06-18 00:10:13

标签: python python-3.x

因此,对于我的程序,我正在尝试创建它,以便如果用户按3,则该程序将打印该收藏集中所有书籍的列表,以及如果用户按4,它将打印该目录中的所有电影。集合,而不是同时存在。我尝试以这种方式合并它,但是每当输入4时,它只会打印标题,而目录中没有任何内容。

#### Import Modules
import inventory


'''------------------------------------------------------
                Main program starts here 
---------------------------------------------------------'''

print("Welcome to BestMedia")
print("====================\n")



# TODO: declare a variable list_items as assign to it
# a call to the initialize the list by calling the initialize
# function in the inventory module.
list_items = inventory.initialize()

# TODO: write a closed loop (while loop with loop test True),
# that keeps executing until the user selects 0. Use a variable
# called command that stores the current user input.
# The loop first displays the menu (by calling the inventory
# display_menu method, then prompts the user to enter a command
# and assigns the input to the command variable.
# Then, in a series of conditional statements, the user input
# if processed: if command=="0": for example.

#Initialize the command with 10 which makes the while true in the first loop
command = 10

#While loop would run till the 0 is the input
while command != 0:

    inventory.display_menu()
    #Store the input in command
    command = int(input("Enter Command:"))

    #Program will exit in case the command is 0
    if command == 0:
        print("Goodbye!")

    #Program calls the display function from the inventory to print the list
    if command == 1:
        inventory.display(list_items, "all")

    if command ==2:
        inventory.info()

    if command == 3:
        inventory.display(list_items,"Books")

    if command == 4:
        inventory.display(list_items,"Movies")


    ## calling the function display for 3 and 4 (this is in another file)

    if command == 3:
        inventory.display(list_items,"Books")

    if command == 4:
        inventory.display(list_items,"Movies")

0 个答案:

没有答案