我已经被这个python问题困扰了好几个小时。我试图找出如何将上面可以手动输入的数据写入到一个txt文件中,使其显示在一个两行八列的表中。name_数组中的内容应该是头,data_数组中的内容是实际的数据片段。在
name = str(raw_input( "Enter the student's name: "))
medianScore = float(raw_input("Enter the median group score for quizzes:"))
indScore = float(raw_input("Enter the score of the individual quiz: "))
assignmentScore = float(raw_input("Enter the score of the assignment: "))
test1Score = float(raw_input("Enter the score of exam one: "))
test2Score = float(raw_input("Enter the score of exam two: "))
test3Score = float(raw_input("Enter the score of the final exam: "))
fileName = str(raw_input("Enter the name of the file you would like to create: "))
f = file(fileName + ".txt" , a)
finalScore = ((medianScore * .14) + (indScore * .14) + (assignmentScore * .12) + (test1Score * .15) +(test2Score * .20) + (test3Score * .25))
data_array = [name, finalScore, test3Score, test1Score, test2Score, assignmentScore, indScore, medianScore]
name_array = [ "Student", "Final Grade", "Final Exam", "Exam 1", "Exam 2", "Assignments", "Solo Quizzes", "Group Quizzes"]
你有没有试过:
如果您只想输出一个类似csv的文件,可以使用
csv
包:它将输出:
^{pr2}$在这个例子中,使用
tab
s作为分隔符,但是您可以用任何字符来替换它。有关更多选项,请参见this documentation。在相反,如果您想要更具可读性的内容,可以使用intead
tabulate
包:它将产生:
请参阅this documentation以获取格式化表的更多选项。在
相关问题 更多 >
编程相关推荐