입니다. 그렇다면이 코드를 사용하여 몇 가지 테스트를 실행하여 주된 문제점을 확인하십시오. 나는 비활성, 그래서 그것을 에드 '# 내가 그래서 전화 번호 입력 유효성 검사에 문제가 발견 (당신은 당신에게 스티커를 lgive 줘야 그 문제를 해결 할 수있는 경우 을 어쨌든 :..전역 이름 목록이 정의되지 않았습니다. 모듈 변수는
def main():
name = []
phone = []
groupno = []
score = []
review = []
q = input('Do you wish to Continue Y/N')
while q != "Y":
def data(name, phone, groupno, score, namelist, groupsizes,phonumber, mealscore):
name = input("Please enter the customer's name.")
namelist.append(name)
#phone = int(input("Please enter the customer's Phone Number."))
#if len.str(phone) == 11:
# else: phone = int(input("Please enter the customer's Phone Number."))
#phonumber.append(phone)
sizeofgroup = int(input('Please enter the size of group: '))
while sizeofgroup < 1 or sizeofgroup > 20:
sizeofgroup = int(input('Please enter a valid group size: '))
groupsizes.append(sizeofgroup)
score = int(input('Please enter the rating of the meal: '))
while score <= 1 or score >= 10:
score = int(input('Please enter the rating of the meal- between 1 and 10: '))
mealscore.append(score)
main()
그리고 난
Do you wish to Continue Y/N?: y Traceback (most recent call last): File "\QRSTORAGE\SMCPupilData$\stirlim\Work\S5\Computing\Coursework
Task\Program\code2.py", line 35, in main() File "\QRSTORAGE\SMCPupilData$\stirlim\Work\S5\Computing\Coursework
Task\Program\code2.py", line 16, in main namelist.append(name) NameError: global name 'namelist' is not defined
어떤 오류 수단하지만 파이썬은 범위 지정에 대한 들여 쓰기를 사용하기 때문에 변수
감사합니다. 이름 목록 섹션이 작동합니다 ^^ 불행히도 전화 내용은 부담스럽지 않지만 ^^ 노력하고 있습니다 ^^ – Minuit
실제로는 식별자에 관한 것이 아니라 기능 정의에 관한 것입니다. 파이썬은 범위 지정을 위해 식별자를 사용하지 않습니다. if 블록 안에 변수를 정의하려고합니다 : if True : my_var = 10; print (my_var)'가 작동합니다;) – ProfHase85