dimanche 25 décembre 2016

else block does not work properly

I try to create a book list in python.

Here are the sample list:

The list contains book_id, bookName, writerName, writerSurname, cost objects.

  books = [
     [45623, 'Ptyhon', 'Mustafa', 'Basak', 23],
     [99878, 'Linux Networks', 'Mustafa', 'Basak', 26],
     [98938, 'Operating Systems', 'Ali', 'Akinci', 17],
     [98947, 'PHP and AJAX', 'Haydar', 'Baskan', 25]
     ]

I want to search the list according to writer surname.

 while 1:
     writerSurname = input('Pls enter the writer's surname.')
     if writerSurname not in ['exit', 'Exit']:
         for k in books:
             if str(writerSurname) == k[3]:
                 print(k[1],'writer', k[2],k[3], "cost is", k[4],"TL")

     else:
         print(writerSurname, 'there is no such a person.')
         break

But else block does not work properly. When I type a surname which is not in book list, it does not show print(writerSurname, 'there is no such a person.') line. Can someone advise where I do make a mistake ?

Aucun commentaire:

Enregistrer un commentaire