Upload
andrew-carts
View
115
Download
0
Embed Size (px)
DESCRIPTION
MCC
Citation preview
Python Code (for Reference)
def main(): examanswerkey = ['a', 'c', 'a', 'a', 'd', 'b', 'c', 'a', 'c', 'b', 'a', 'd', 'c', 'a', 'd', 'c', 'b', 'b', 'd', 'a']
outfile = open('examanswers.txt', 'w') for item in examanswerkey: outfile.write(item + '\n') outfile.close() print("Correct answers written to examanswers.txt.")
answers = []
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) outfile = open('answers.txt', 'w')
for item in answers: outfile.write(item + '\n')
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')
wrongAnswers = correctedList.count("XX") correctAnswers = (20 - wrongAnswers)
print("Correctly answered questions: ", correctAnswers) print("Incorrectly answered questions: ", wrongAnswers)
if correctAnswers >= 15: print("The Candidate has passed the DL Exam!") else: print("The Candidate has failed the DL Exam. Please Retry another time.")
print("Your incorrect answers are marked 'XX': ", (correctedList)) main()
Assignment #5 Pseudocode:
STARTCreate List called examanswerkey and populate with correct answersOpen a file named examanswers.txtWrite List (examanswerkey) to examanswers.txtClose the examanswers.txt fileDisplay message Correct answers written to examanswers.txtCreate an empty List called answers Create variable questionNum and set equal to 1While length(answers) is <= 19
Display message Enter DL Candidate answer for %d(questionNum)questionNum = questionNum + 1Read inputAppend List (answers)
EndwhileOpen a file named answers.txtWrite List (answers) to answers.txtClose the answers.txt fileDisplay message DL Candidate s answers have been written to answers.txt Create empty List (correctedList)For I in range (len(answers))
if answers == examanswersappend List(correctedList) with Candidate answers
elseappend 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
START
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
While length <= 19
Display message enter answer
Add 1 to questionNum
Read input
Append List(answers)
Open file named answers.txt
TRUE
FALSE
Write List(answers) to answers.txt
Close answer.txt
Display message
Create Empty List(correctedList)
For i in range (answers)
If answers == examanswers
Append list(correctedList)
with Candidate answers
Append List(correctedList)
with XX
Yes No
Declare variable wrongAnswers
and set to number of XX in
correctedList
Delcare variable correct answers and
set to 20 - wrongAnswers
A
A
If correctAnswers
> 15
Display message Pass
Display message Fail
Display message with correctedList
for wrong answers
Display message correctAnswers
Display message wrongAnswers
YesNo