我不能让len命令工作

2024-05-29 01:43:29 发布

您现在位置: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')

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


Tags: thenumberlenifisprintpleasetry
1条回答
网友
1楼 · 发布于 2024-05-29 01:43:29

就像注释中提到的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

相关问题 更多 >

    热门问题