def menu(): print("- - - - - - - -- PROGRAM MENU -- - - - - - - -") print("Welcome Library V1.0, what would you like to do? \n") print("1 ) Add a book") # Adds a book to the library. print("2 ) List a specific book's details") # Prints the library's titles and let the user select one for more details. print("3 ) List all recorded complete book details") # Prints all library info. menu_Choice = input("4 ) Exit.\n\n") if menu_Choice == 1: add_book() elif menu_Choice == 2: list_book() elif menu_Choice == 3: list_all() elif menu_Choice == 4: exit() else: print("Error: Please enter a number as shown and try again.") print("-----------------------------------------------------------\n\n") menu() def add_book(): # Adds a book to the library. Restart() def list_book(): # Lists all titles of the library and lets the user choose which book they want additional information on. Restart() def list_all(): # Lists all contents of the library. print(main()) #for key in myLibrary: print(myLibrary[key]) -- Convert this to get the function to actually work. def elsePhrase(): # Used within the Restart function. print("Wrong input, I'll just send you back to the menu.\n") menu() def Restart(): # Asks the user if they would rather go to the main menu or exit the program. toMenu = raw_input("\n\tWould you like to go back to the main menu? Y / N\t\n\n") if toMenu == "Y": menu() elif toMenu == "N": toExit = raw_input("Oh.. Okay then want me to just exit the program? Y /N\n\n") if toExit == "Y": exit() elif toExit == "N": print("Alright, I guess I'll just leave you be, you know where the big red X button is I guess. Take your time.") else: elsePhrase() else: elsePhrase() def main(): print("Test to see if this is running") lib = {} book1 = {'title':'Alice and the Giant Turtle','author':'Lewis Stivalson','page count':'421', 'publish date':'1-20-2010'} #Sample book 1 book2 = {'title':'Rainbow Explosions','author':'Clancy Ranso','page count':'322','publish date':'October 8th 1998'} # Sample book 2 lib['ID-1'] = book1 lib['ID-2'] = book2 passInteger = 0 return lib menu()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question