将从调查问卷收集的信息发送到Python文档?

时间:2016-03-15 02:24:42

标签: python

我对Python和StackOverflow都是全新的,我有一个问题,在过去的几个小时里一直困扰着我。

我正在为我的高中班制作同伴评估脚本。当您运行脚本时,输入您的同学姓名,然后根据努力,责任和参与对其进行评分1-10。然后对这3个值进行平均。该平均值被分配给变量“grade”。由于每个同学都要获得多个等级,我需要将“等级”变量导出到另一个Python文档,在那里我可以平均每个等级的每个等级。

到目前为止,我让脚本创建了一个与评估的同学同名的.txt文件,并在那里存储了等级整数。有没有人知道我可以将这个整数导出到Python文件的方法,我可以附加每个连续的等级,然后可以对它们进行平均?

由于

Python对等评估脚本

def script():     classmate = input('请输入你同学的名字:')

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()

脚本()

1 个答案:

答案 0 :(得分:0)

import name_of_script_file

位于Python文件的顶部,假设它们位于同一个文件夹中。

然后您可以访问变量,如:

name_of_script_file.variable_name