我在三種不同的方式嘗試這個節目,我知道我接近了幾次,但失敗了這麼多次我都放棄了,需要一組額外的眼睛之後。 我知道這個程序是「簡單的」,但我知道我在想這件事。的Python 3.3 - 多選名單,從閱讀和.txt然後
程序應該在列表中存儲正確答案。使用該列表對20個問題測試進行評分。 然後閱讀該student.txt文件,以確定學生如何回答。 閱讀.txt文件後,它應該評分,然後顯示通過或失敗(通過= 15或更大) 它終於顯示總數或正確的,不正確的答案與學生錯過的問題列表。
下面是所有三次嘗試。任何幫助是極大的讚賞。
3210
# This program stores the correct answer for a test
# then reads students answers from .txt file
# after reading determines and dislpays pass or fail (15 correct to pass)
# Displays number of correct and incorrect answers for student
# then displays the number for the missed question/s
#Creat the answer list
def main ():
# Create the answer key list
key = [ B, D, A, A, C, A, B, A, C, D, B, C, D, A, D, C, C, B, D, A,]
print (key)
# Read the contents of the student_answers.txt and insert them into a list
def read_student():
# Open file for reading
infile = open ('student_answers.txt', 'r')
# Read the contents of the file into a list
student = infile.readlines ()
# Close file
infile.close ()
# Strip the \n from each element
index = 0
while index < len(student):
student[index] = student[index].rstrip ('\n')
# Print the contents of the list
print (student)
# Determine pass or fail and display all results
def pass_fail(answers, student):
# Lists to be used to compile amount correct,
# amount wrong, and questions number missed
correct_list = []
wrong_list = []
missed_list = []
# For statement to compile lists
for ai,bi in zip (key,student):
if ai == bi:
correct_list.append(ai)
else:
wrong_list.append(ai)
missed_list.append(ai)
# Printing results for user
print(correct_list,' were answered correctly')
print(wrong_list,' questions were missed')
# If statement to determine pass or fail
if len(correct_list) >=15:
print('Congrats you have passed')
else:
print('Sorry you have faild please study and try, \
again in 90 days')
print('Any attempt to retake test before 90 days, \
will result in suspension of any licenses')
# Displaying the question number for the incorrect answer
print ('You missed questions number ', missed_list)
main()
a = (1, 'A'),(2,'C'),(3,'B')
b = (1,'A'), (2,'A'),(3,'C')
correct_list = []
wrong_list = []
missed_list = []
for ai, bi in zip (a, b):
if ai == bi:
correct_list.append(ai)
else:
wrong_list.append(ai)
missed_list.append(ai)
index(ai)+1
print(correct_list,'answered correct')
print(wrong_list, 'answered wrong')
if len(correct_list) >=2:
print ('Congrats you have passed')
else:
print ('Sorry you have faild please study and try again in 90 days')
print('Any attempt to retake test before 90 days will result in suspension of any lisences')
print ('Question number missed', missed_list)
什麼不行? – Blender
如何編寫txt文件?單行,逗號分隔,或每個答案的新行? –