2016-11-14 150 views
0

嘿傢伙們基本上我試圖使用FOR循環來詢問演員和女演員的用戶名搜索並打印出某個演員是否在電影中以及如果他們不是在電影裏。到目前爲止,林很堅持,不知道怎麼問我的代碼爲我的演員Python 2.7使用FOR循環

print ("Which actor/actress you want to look for?") 
actors [] 
for actor in actors: 
    If actor == actors: 
    print ("Yes, %s is in the show breaking bad") (actors,) 
    break 
    else: 
    print ("NO , %s is not in the show breaking bad") (actors,) 
    print actor 

回答

0

看起來你有基本的想法,但你的代碼是所有的地方。

試着這麼做:

search_name = raw_input('Please enter the actor to search for: ') 
actors = ['Idris Elba', 'Dwayne Johnson', 'Mel Brooks'] 

if search_name in actors: 
    print search_name + 'is in the movie!' 
else: 
    print search_name + 'is NOT in the movie!' 

如果你想繼續問,直到輸入列表的名稱,使用循環:

search_name = raw_input('Please enter the actor to search for: ') 
actors = ['Idris Elba', 'Dwayne Johnson', 'Mel Brooks'] 

while search_name not in actors: 
    print search_name + 'is NOT in the movie!' 
    search_name = raw_input('Please enter a different actor's name:') 

print search_name + 'is in the movie!'