Sending information gathered from questionnaire to a Python document?
Question: I'm brand new to both Python and StackOverflow, and I have a problem that has
been stumping me for the past couple of hours.

I am making a peer-evaluation script for my high-school class. When you run
the script, you input your classmate's name, then you rate them 1-10 on
effort, accountability, and participation. These 3 values are then averaged.
This average is assigned to the variable "grade". Since each classmate is
going to get multiple grades, I need to have the "grade" variable export to
another Python document where I can average every grade for each respective
classmate.

So far, I have the script create a .txt file with the same name as the
evaluated classmate, and the grade integer is stored there. Does anyone know
of a way that I can export that integer to a Python file where I can append
each successive grade so they can then be averaged?

Thanks

# Python peer evaluation script

def script(): classmate = input('Please enter your classmate\'s name: ')

    
    
    classmateString = str(classmate)
    
    effortString = input('Please enter an integer from 1-10 signifying your classmate\'s overall effort during LLS: ')
    
    effort = int(effortString)
    
    accountabilityString = input('Please enter an integer from 1-10 signifying how accountable your classmate was during LLS: ')
    
    accountability = int(accountabilityString)
    
    participationString = input('Please enter an integer from 1-10 signifying your classmate\'s overall participation: ')
    
    participation = int(participationString)
    
    add = effort + accountability + participation 
    
    grade = add / 3
    
    gradeString = str(grade)
    
    print ('Your grade for ', classmate, 'is: ', grade)
    
    print ('Thank you for your participation. Your input will help represent your classmate\'s grade for the LLS event.')
    
    filename = (classmateString)+'.txt'
    
    file = open(filename, 'a+')
    
    file.write(gradeString)
    
    file.close()
    
    print ('Move on to next classmate?')
    yes = set(['yes','y','Yes','Y'])
    no = set(['no','n','No','n'])
    
    choice = input().lower()
    if choice in yes:
        script()
    elif choice in no:
        sys.exit(0)
    else:
        sys.stdout.write("Please respond with 'yes' or 'no'")
    script()
    

script()


Answer: put

    
    
    import name_of_script_file
    

at the top of your Python file, assuming they are in the same folder.

Then you can access the variable like:

    
    
    name_of_script_file.variable_name
    

