Assignment 5
Assignment 5
Assignment 5
START
START
Create List called examanswerkey and populate with correct answers
Open a file named examanswers.txt
Write List (examanswerkey) to examanswers.txt
Close the examanswers.txt file
Display message Correct answers written to examanswers.txt
Create an empty List called answers
Create variable questionNum and set equal to 1
While length(answers) is <= 19
Display message Enter DL Candidate answer for %d(questionNum)
questionNum = questionNum + 1
Read input
Append List (answers)
Endwhile
Open a file named answers.txt
Write List (answers) to answers.txt
Close the answers.txt file
Display message DL Candidate s answers have been written to answers.txt
Create empty List (correctedList)
For I in range (len(answers))
if answers == examanswers
append List(correctedList) with Candidate answers
else
append List(correctedList) with XX
Declare variable (wrongAnswers) and set to number of XX in List(correctedList)
Declare variable (correctAnswers) and set to (20 wrongAnswers)
If correctAnswers >= 15:
Display message Candidate has passed
Else
Display message Candidate has failed
Display message with List(correctedList)
END
Create
List(examanswerkey)
Open examansers.txt
Write
list(examanswerkey)
to file
Display message
Create empty
List(answers)
Create variable
questionNum and set
to 1
TRUE
Display message
enter answer
Add 1 to questionNum
FALSE
Read input
Open file named
answers.txt
Append List(answers)
Write List(answers)
to answers.txt
Close answer.txt
Display message
Create Empty
List(correctedList)
outfile.close()
print("Correct answers written to examanswers.txt.")
Yes
answers = []
Append
list(correctedList)
with Candidate
answers
Declare variable
wrongAnswers
and set to
number of XX in
correctedList
questionNum = 1
while len(answers) <= 19:
student_answers = input("Enter the DL Candidate's answer for the question #%d (use only
lower case letters)" %(questionNum))
questionNum = questionNum + 1
answers.append(student_answers)
Delcare variable
correct answers and
set to 20 wrongAnswers
Display message
correctAnswers
outfile.close()
print("The DL Candidate's answers have been written to the file answers.txt.")
correctedList = []
for i in range(len(answers)):
if answers[i] == examanswerkey[i]:
correctedList.append(answers[i])
else:
correctedList.append('XX')
Display message
wrongAnswers
No
wrongAnswers = correctedList.count("XX")
correctAnswers = (20 - wrongAnswers)
print("Correctly answered questions: ", correctAnswers)
print("Incorrectly answered questions: ", wrongAnswers)
If
correctAnswers
> 15
Display message
Fail
Yes
Display message
Pass
Display message
with corrected List
for wrong
answers
main()
END
If answers ==
examanswers
No
Append
List(correctedList)
with XX