I have code like this:
from tabulate import tabulate
def search_movie_title():
movies = open('movies.txt','r').readlines()
title = input("Input movie title: ").lower()
for i in movies:
movie = i.strip("\n").split("|")
if title == movie[0].lower():
table = [['Name:',movie[0]],['Genre:',movie[1]],['Running:',movie[2]],['Director:',movie[3]],['Starring:', movie[4]],['Country:', movie[5]], ['Realised:', movie[6]]]
print (tabulate(table))
else:
print("Nothing found! Try again.")
search_movie_title()
And text file like this:
A fistful of Dolars|Western|100|Sergio Leone|Clint Eastwood|Italia|1964
For a few dolars more|Western|130|Sergio Leone|Clint Eastwood|Italia|1965
The Good, the Bad and the Ugly|Western|179|Sergio Leone|Clint Eastwood|Italia|1966
March on the Drina|War movie|107|Zika Mitrovic|LJuba Tadic|Serbia|1964
If I use use only if statement it works "fine", but if I input nonexistent movie, then program just stop running, obvious.
In case I use if and else it will always print else statement (except for first line in text file)
Question is: How to print only found movie and how to print message if movie is not found?
Aucun commentaire:
Enregistrer un commentaire