나는 학생들이 완료해야하는 과업 과제에 대한 솔루션을 개발하려고 노력 중이며, 함수간에 변수를 전달하는 데 주저합니다. 나는 다음과 같은 데이터를 생성하는 함수 내에서 퀴즈를 만들었습니다 : 나는 두 번째 함수로이 데이터를 전달해야 하나의 함수에서 다른 함수로 변수에 데이터 전달하기
점수
- 이름을 그 다음 것 이 데이터를 파일에 추가하십시오 (학생이 속한 그룹에 따라 다름). 내가 매개 변수로 두 번째 함수에 문자열/목록으로 데이터를 전달하기 위해 시도로
내 코드는 다음과 같습니다
def Quiz(): #Code to collect user details and generate scoe (10 random questions) strSave=input("Do you want to save your score? y/n") if strSave.lower()=="y": result=(strFirstName+","+strLastName+","+str(score)) #Stores the required data as a csv string return result #?passes the data back? funcSave() elif strSave.lower()=="n": funcQuiz() #restarts the quiz function def funcSave(result): #The function to save the score(s) to file group=input("Which group are you A1, A2 or A3?\n") if group=="A1": file=open("A1.txt","a") file.write(result) #error is that result is not defined file.close() elif group=="A2": file=open("A2.txt","a") file.write(strFirstName+","+strLastName+","+str(score)) file.close() elif group=="A3": file=open("A3.txt","a") file.write(strFirstName+","+strLastName+","+str(score)) file.close() else: print("unknown")
고마워요. 정말로 도움이되고 문제를 설명 할뿐만 아니라 해결 방법을 설명해주었습니다. –