My list:
listOfMovies=[the Slow and Confused 9, Somebody, Gorilla vs. King, The Blundering 3: Boss Made Me Do It]
I am trying to take an input and if there is a match to the list, the function will print out the object.
If there is no match, the function will print out and ask if I would like to search again or return to the mainmenu.
No results found
1. Search again
2. Return to Main Menu
Currently I am able to print the matches however, I also print out the no results as well.
If there are no matches with the input, I want No results to be printed.
I would like to print out the matches and skip printing the no results found.
My code is:
def DisplayMovie( movie, i ):
print ( "Movie Name: " + str(movie[i].getName()) + ",", "Category:" , movie[i].getCategory())
return
def SearchBasedOnName(searchString, listOfMovies):
for i in range ( len(listOfMovies) ):
if (searchString.lower() in listOfMovies[i].getName().lower()):
DisplayMovie( listOfMovies, i)
print("\nNo results found")
print("1. Search again")
print("2. Return to Main Menu")
option3input = input("")
if option3input == "1":
searchString = input("\nPlease enter your search input: \n")
elif option3input == "2":
printMenu()
searchString = input("\nPlease enter your search input:")
SearchBasedOnName(searchString, listOfMovies)
The output I get:
Please enter your search input: king
Movie Name: Gorilla vs. King
No results found
1. Search again
2. Return to Main Menu
Aucun commentaire:
Enregistrer un commentaire