所以这是我的代码:
membership_data = open("C:\\Users\\user\Desktop\Pre-release\membership_data.txt", "w")
def ValidateMemberID(MemberID):
if len(MemberID) !=6:
return("Wrong Format")
elif MemberID[:1] == (MemberID[:1]).lower():
return("Wrong Format")
elif MemberID[1:3] == (MemberID[1:3]).upper():
return("Wrong Format")
elif (MemberID[3:]).isdigit() == False:
return("Wrong Format")
else:
return("Correct Format")
def inputdata():
Name = input("Please input member name")
MemberID = input("Please input member ID")
ValidateMemberID(MemberID)
if ValidateMemberID(MemberID) == "Correct Format":
NameID = [Name, MemberID, "\n"]
else:
print ("Invalid MemberID")
membership_data.writelines(NameID)
for _ in range(5):
do()
inputdata(_)
membership_data.close
我得到的问题是:
Traceback (most recent call last):
File "C:\Users\user\Desktop\Pre-release\task_3.1.py", line 31, in <module>
do()
NameError: name 'do' is not defined
我想要做的是在我的程序的第一个实例上输入5个不同的记录。基本上我需要运行inputdata()
5次。但是,我的for in range do
函数不断回复此错误。我尝试了不同的写作方式,但无济于事。
答案 0 :(得分:1)
我认为你必须从你的代码中删除'do()'
for x in range(5):
inputdata()
membership_data.close()