2016-02-03 82 views
-3
while True : 
Vehicle_Number_PLate = ('Please enter the vehicles number plate: ') 
If len(Vehicle_Number_Plate)>7: 
    print ('The number plate is invalid, please try again') 
    Vehicle_Number_plate = FALSE 
If len(Vehicle_Number_Plate)<7: 
    print ('The number plate is invalid, please try again') 

請你能幫助我,我真的卡住了,我需要幫助。非常感謝我不能得到len命令工作

+4

'如果'是'if',''while'需要一個縮進。 –

+2

使用輸入('請輸入車號牌') – tinySandy

+0

另外,'print'是一個很好的調試工具。嘗試'print(Vehicle_Number_Plate)',你會看到問題。 – tdelaney

回答

1

像在評論中提到If應該ifFALSE應該是False。要獲得用戶輸入,請使用input('Please enter the vehicles number plate: ')。您需要正確的縮進並且變量與if中的變量不匹配。我相信這樣的東西就是你要找的東西:

valid=False 
while not valid: 
    Vehicle_Number_Plate = input('Please enter the vehicles number plate: ') 
    if len(Vehicle_Number_Plate)!=7: 
     print ('The number plate is invalid, please try again') 
    else: 
     print ('The number plate is valid') 
     valid=True 
+0

如果小於7,OP也會失效。 – tdelaney

+0

固定以反映原始問題,'else'是我想要的東西 – depperm