函数不打印两个单独的打印语句

Function not Printing two separate print statements

我是个人项目的新手,正在通过 python 终端开发图书馆图书管理系统。

我 运行 遇到了一个已被卡住一段时间的问题。

我正在尝试将我的代码打印到控制台

------ 主菜单 ------

  1. 所有书籍
  2. 签到
  3. 退房
  4. 查找

但它只是一遍又一遍地给我“选择选项”。我不确定我做错了什么,因为我已经试过很多次了,但我找不到解决办法。

源代码:

终端输出:

以后尝试将您的代码直接粘贴到您的问题中,而不是作为图像。

无论如何,尝试移动以 option 开头的行,即:

option = input("Choose options: ")

进入mainMenu里面 函数(main_menu在你下面尝试重建的尝试):

#
#
# Print menu
# Menu will include a list if menu options
# Create a main menu function that will control the main menu
# Then call functions as they are requested by the user
# Will require a dictionary using id's as the key and book info as values
#
#

import pprint
import os

# Books in the System
books = [
    {"ID": 100001, "title": "Meditations", "author": "Marcus Aurelius", "year": 180},
    {"ID": 100002, "title": "To Kill a Mockingbird", "author": "Harper Lee", "year": 1960},
    {"ID": 100003, "title": "The Great Gatsby", "author": "F. Scott Fitzgerald", "year": 1925},
    {"ID": 100004, "title": "Don Quixote", "author": "Miguel de Cervantes", "year": 1615},
    {"ID": 100005, "title": "The Little Prince", "author": "Antoine de Saint-Exupery", "year": 180}
]

menu = " ------ Main Menu ------ \n\n 1. All Books \n 2. Check In \n 3. Check Out \n 4. Look Up \n"


def menu1():
    pprint.pprint(books)
    option1 = input("Type 0 to go back: ")
    if option1 == "0":
        os.system("clear")
        return main_menu()


def main_menu():
    print(menu)
    option = input("Choose option: ")
    if option == "1":
        os.system("clear")
        return menu1()


if __name__ == '__main__':
    main_menu()

用法示例:

 ------ Main Menu ------ 

 1. All Books 
 2. Check In 
 3. Check Out 
 4. Look Up 

Choose option: 1
[{'ID': 100001,
  'author': 'Marcus Aurelius',
  'title': 'Meditations',
  'year': 180},
 {'ID': 100002,
  'author': 'Harper Lee',
  'title': 'To Kill a Mockingbird',
  'year': 1960},
 {'ID': 100003,
  'author': 'F. Scott Fitzgerald',
  'title': 'The Great Gatsby',
  'year': 1925},
 {'ID': 100004,
  'author': 'Miguel de Cervantes',
  'title': 'Don Quixote',
  'year': 1615},
 {'ID': 100005,
  'author': 'Antoine de Saint-Exupery',
  'title': 'The Little Prince',
  'year': 180}]