[Tutor] A question

Sara Mn saramn610 at gmail.com
Thu Apr 2 04:49:56 EDT 2020


Hello Sir/Madam,
I have a question regarding passing arguments to another function, I have made this code fragment:

def question1():
    print("Q1) What subject of the below subjects you find most intresting:\na-Biology\nb-Chemistry\nc-Math\nd-Physics\ne-Business Studies\nf-Computer Science\ng-Art")
    answer1=input("Enter your answer's letter Or enter X to exit the program: ").lower()
    if answer1 in  answerList1 :
        return answer1
    
    elif answer1=='x':
        sys.exit(0)
   
    else:
        while True:
            print("\nThe answer you entred is invalid, you have two more tries. If you wish to exit the program enter X")
            answer1=input("Enter your answer: ")
            if answer1 in answerList1 :
                
                return answer1
                break
            elif answer1=='x':
                sys.exit(0)
            else:
                print("The answer you entred is invalid, you have one more try. If you wish to exit the program enter X")
                answer1=input("Enter your answer: ")
                return answer1 
            if answer1 in answerList1:
                
                return answer1 
                break
            elif answer1=='x':
                sys.exit(0)
                
            else:
                print("The answer you entred is invalid. The program is being terminated as you have reached your maximum number of tries") 
                sys.exit(0)

def AnswerCollection():
    n1=question1()
    print(n1)


However I can’t just pass the local variable answer1 to the function AnswerCollection() it passes the whole function with the question.
What can I do to pass only the local variable. Also, I have 6 different functions with the same format. How can I pass 6 different local variables from 6 different functions to one function.


Thank You .


More information about the Tutor mailing list