Для первого бита, как я распечатать «ask2», он печатает «выход», в отличие от номерного знака, что, как предполагается, будет печатать.код не печатает то, что я ищу
ask = input("-Would you like to 1 input an existing number plate\n--or 2 view a random number\n1 or 2: ")
ask2 = ""
plate = ""
if int(ask) == 1:
ask2 = ""
print("========================================================================")
while ask2 != 'exit':
ask2 = input ("Please enter it in such form (XX00XXX): ").lower()
# I had no idea that re existed, so I had to look it up.
# As your if-statement with re gave an error, I used this similar method for checking the format.
# I cannot tell you why yours didn't work, sorry.
valid = re.compile("[a-z][a-z]\d\d[a-z][a-z][a-z]\Z")
#b will start and end the program, meaning no more than 3-4 letters will be used.
# The code which tells the user to enter the right format (keeps looping)
# User can exit the loop by typing 'exit'
while (not valid.match(ask2)) and (ask2 != 'exit'):
print("========================================================================")
print("You can exit the validation by typing 'exit'.")
time.sleep(0.5)
print("========================================================================")
ask2 = input("Or stick to the rules, and enter it in such form (XX00XXX): ").lower()
if valid.match(ask2):
print("========================================================================\nVerification Success!")
ask2 = 'exit' # People generally try to avoid 'break' when possible, so I did it this way (same effect)
**print("The program, will determine whether or not the car "+str(plate),str(ask)+" is travelling more than the speed limit")**
Также я ищу несколько хороших кодов, которые хороши для добавления (ввод данных в списке), и печать. Это то, что я сделал;
while tryagain not in ["y","n","Y","N"]:
tryagain = input("Please enter y or n")
if tryagain.lower() == ["y","Y"]:
do_the_quiz()
if tryagain==["n","N"]:
cars.append(plate+": "+str(x))
print(cars)
Ваш вопрос непонятен. Пожалуйста, напишите * только * соответствующую часть кода, и уточните свой вопрос: когда вы спрашиваете: «Почему он печатает x?» не забудьте показать нам, какая строка в коде делает это, каков был вклад, который вы предоставили, и т. д. Удачи! – alfasin
Вы говорите, что ask2 печатается как «выход», но я не вижу нигде в коде, который вы опубликовали, который фактически распечатывает ask2. Я вижу, что вы задаете ask2 «exit», если 'valid.match (ask2)' true; возможно, именно поэтому? –