# Imports
import re
# Variables
contestants = []
def run(string):
incorrectSymbols = re.compile('[@_!#$%^&*()<>?/\|}{~:]')
if (incorrectSymbols.search(string) == None):
return "yes"
else:
return "no"
def bootUp():
print(""">>> Hello judges!
>>> Today you will be viewing 6 contestants!
>>> To continue please enter all contestants names!""")
contestantNames()
def contestantNames():
for i in range(0, 6):
while True:
x = input(">>> Contestant number " + str(i) + " name: ")
if run(x) == "yes":
break
elif run(x) == "no":
print(">>> No symbols allowed!")
elif x=="": # Here is what im confused about.
print(">>> You can't leave it blank!")
else:
print(">>> Error in run function.")
contestants.append(x)
print(contestants)
bootUp()
阅读完此问题后,我发现有多个帐户都说只需使用(variable)=“”即可。但是,这对我不起作用,还有其他想法吗?
我的代码是一个舞蹈项目的尝试,参与者都轮流参加,每个法官为每个参与者评分。简单地说就是锦标赛。这部分代码将是我获取参赛者姓名的开始,并且我需要确保他们没有符号或留空。
run
无法按预期工作。其返回的“是”和“否”不是对与错。如果您订购的其他产品不正确,则需要修复该问题。if x==''
条件,它将起作用。# Imports
import re
# Variables
contestants = []
def run(string):
incorrectSymbols = re.compile('[@_!#$%^&*()<>?/\|}{~:]')
if (incorrectSymbols.search(string) == None):
return "yes"
else:
return "no"
def bootUp():
print(""">>> Hello judges!
>>> Today you will be viewing 6 contestants!
>>> To continue please enter all contestants names!""")
contestantNames()
def contestantNames():
for i in range(0, 6):
while True:
x = input(">>> Contestant number " + str(i) + " name: ")
if x == "": # Here is what im confused about.
print(">>> You can't leave it blank!")
elif run(x) == "yes":
break
elif run(x) == "no":
print(">>> No symbols allowed!")
else:
print(">>> Error in run function.")
contestants.append(x)
print(contestants)
bootUp()
def run(string):
if string == "":
return
incorrectSymbols = re.compile('[@_!#$%^&*()<>?/\|}{~:]')
if (incorrectSymbols.search(string) == None):
return "yes"
else:
return "no"
如果需要其他订购,则可以使用您的默认设置。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句