首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将从调查问卷收集的信息发送到Python文档?

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

Stack Overflow用户
提问于 2016-03-15 10:24:42
回答 1查看 28关注 0票数 0

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

我正在为我的高中班级做一个同行评测脚本。当你运行脚本时,你输入你同学的名字,然后在努力、责任和参与程度上给他们打1-10分。然后对这3个值求平均值。这个平均值被赋值给变量"grade“。由于每个同学将获得多个成绩,因此我需要将" grade“变量导出到另一个Python文档中,在该文档中我可以对每个同学的每个成绩进行平均。

到目前为止,我让脚本创建了一个与被评估的同学同名的.txt文件,并将成绩整数存储在那里。有没有人知道一种方法,我可以把这个整数导出到一个Python文件中,在这个文件中,我可以附加每个连续的分数,这样它们就可以求平均值了?

谢谢

Python同级评估脚本

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

代码语言:javascript
复制
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()

EN

回答 1

Stack Overflow用户

发布于 2016-03-15 10:30:04

代码语言:javascript
复制
import name_of_script_file

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

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

代码语言:javascript
复制
name_of_script_file.variable_name
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36001600

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档