assignment 5

1
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: 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 Candidates 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 START END Creat e List(examanswerkey) Open e xa manse rs.txt Write list(examanswerke y) to file Display me ssage Creat e e mpty List(answer s) Creat e va riable questionNum a nd set to 1 While length <= 19 Display me ssage enter answer Add 1 to questionNum Read input Append List(answer s) Open file named answer s.txt TRUE FALSE Write List(answer s) to answers.txt Close answer.txt Display me ssage Creat e E mpty 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 wrongAn swers and set to number of XX in correctedList Delcare var iable cor rect answer s and set to 20 - wrongAnswer s A A If correctAnswers > 15 Display me ssage Pa ss Display me ssage Fail Display message with correctedList fo r wrong answers Display me ssage cor rectAnswer s Display me ssage wrongAnswer s Yes No

Upload: andrew-carts

Post on 21-Feb-2016

115 views

Category:

Documents


0 download

DESCRIPTION

MCC

TRANSCRIPT

Page 1: Assignment 5

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