我无法让len命令工作

时间:2016-02-03 18:21:01

标签: python

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')

请你能帮助我吗,我真的被困住了,我需要帮助。非常感谢

1 个答案:

答案 0 :(得分:1)

评论中提到的If应为if,而FALSE应为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
相关问题