2015-12-10 124 views
-3

如何檢查列表中是否有內容? 這是我當前的代碼:將用戶輸入與Python中的列表進行比較

for line not in line: open("drivers_details.txt"): 
       if reg not in line: 
        name=input("what is your name?\n") 
        address=input("what is your address\n") 
        print (reg,name,address,"%0.2f"%average_time,"MPH") 

(我試圖用「不」,但它沒有工作)

+0

您不能運行循環播放不在列表中的內容。一個循環基本上遍歷列表中的每個值,所以顯然這個循環永遠不會是真的。有關解決方案,請參閱http://stackoverflow.com/questions/22833893/python-if-not-in-list。 – Munir

回答

0

我想你想:

for line in open("drivers_details.txt"): 
    if reg not in line: 
     etc. 
相關問題