我如何让它不返回“brea outside loop”。我已经阅读了关于stackoverflow的多个其他答案,但无法理解这个概念,因为它在一个单独的函数中。你知道吗
def dayEntry(book,cmd):
for x,type in zip(list, gettype):
entry = input('?: ')
validate(entry,type)
results.append(entry)
print (results)
def validate(inval, intyp):
if intyp == "date":
try:
datetime.datetime.strptime(inval, '%d-%m-%Y')
except ValueError:
print("Format not valid, use DD-MM-YYYY")
break
将validate函数设置为
return
某个指示有错误的内容,然后如果返回该内容,则中断循环。你知道吗您必须在循环内执行
break
。你知道吗很简单:您的
break
语句不在循环中。它在一个if
语句中。你知道吗相关问题 更多 >
编程相关推荐