Python Forum
Help printing any items that contains a keyword from a list
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help printing any items that contains a keyword from a list
#10
(May-06-2017, 07:43 PM)ichabod801 Wrote: You need elif, which is an abbreviation for 'else if'. It gives another condition to check if the previous conditions haven't been met.

menu()
selection = input('What is your command? ').lower()
if command == 's':
    print('Spam spam spam spam')
elif command == 'c':
    print(1, 2, 5)
elif command == 'i':
    print('Nobody expects the Spanish Inquisition!')
else:
    print('Unknown command')
Typically, this sort of command checking is done in a while True: loop, with a break if the command is q, or quit, or exit, or something like that.


So for examples sake would I place that in here and then do it for each command?

selection=input("Please Select:")
l = file = open("C:\\Users\\LiquidO\\Desktop\\Assingment 2 python\\movies.txt", "r")
if selection =='l':
    movies_list = file.readlines()
    movies_list = [movie.strip() for movie in movies_list]
    print("Movies now loaded")
elif selection == 'r':
 print("Random choice selected")
r = print(random.choice(movies_list))
else:
    print ("Unknown Command")
Reply


Messages In This Thread
RE: Help printing any items that contains a keyword from a list - by Liquid_Ocelot - May-06-2017, 07:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to parse and group hierarchical list items from an unindented string in Python? ann23fr 1 615 May-23-2024, 05:39 AM
Last Post: Pedroski55
  Collisions for items in a list Idents 3 2,461 Apr-06-2021, 03:48 PM
Last Post: deanhystad
  Removing items in a list cap510 3 2,480 Nov-01-2020, 09:53 PM
Last Post: cap510
  Help with Recursive solution,list items gianniskampanakis 8 3,855 Feb-28-2020, 03:36 PM
Last Post: gianniskampanakis
  Removing items from list slackerman73 8 4,665 Dec-13-2019, 05:39 PM
Last Post: Clunk_Head
  Find 'greater than' items in list johneven 2 4,640 Apr-05-2019, 07:22 AM
Last Post: perfringo
  How to add items within a list Mrocks22 2 2,805 Nov-01-2018, 08:46 PM
Last Post: Mrocks22
  printing list of random generated rectangles Zatoichi 8 7,551 Feb-18-2018, 06:34 PM
Last Post: buran
  How to keep duplicates and remove all other items in list? student8 1 5,086 Oct-28-2017, 05:52 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020