Код: Выделить всё
ask2 = ""
plate = ""
if int(ask) == 1:
stop = False
time.sleep(0.5)
print("========================================================================")
while not stop:
ask2 = input("Please enter it in such form (XX00XXX): ").lower()
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'
# This is the default exit_message
exit_message = "Verification Failed!"
while (not valid.match(ask2)) and (ask2 != 'exit'):
time.sleep(0.5)
print("========================================================================\n", exit_message,
sep="")
print("You can exit the validation by typing 'exit'.")
time.sleep(0.5)
print("========================================================================")
time.sleep(0.5)
ask2 = input("Or stick to the rules, and enter it in such form (XX00XXX): ").lower()
if ask2 == 'exit':
exit_message = "Verification Stopped!"
stop = True
break
Код: Выделить всё
var = input("no caps: ")
def isvalid(s):
for i in s:
if i in "ABC...XYZ":
return False
return True
while not isvalid(var):
def isvalid(s):
for i in s:
if i in "ABC...XYZ":
return False
return True
Подробнее здесь: https://stackoverflow.com/questions/338 ... lize-input