Você está na página 1de 1

Assignment #5 Pseudocode:

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

While length <=


19

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)

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 i in range
(answers)

for item in examanswerkey:


outfile.write(item + '\n')

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

outfile = open('answers.txt', 'w')


for item in answers:
outfile.write(item + '\n')

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:


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))

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

Você também pode gostar