0% found this document useful (0 votes)
7 views3 pages

Adding A Menu

Uploaded by

shuura
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Adding A Menu

Uploaded by

shuura
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Add$ng a Menu

The f$rst enhancement $s that when the program runs, a menu should be d$splayed as $n the
follow$ng $mage, $nstead of start$ng the qu$z $mmed$ately.

⸻--WELCOME TO THE QUIZ--------


Ava$lable Act$ons:
. Take the game
. Produce report
. Qu$t
Choose one of the act$ons above (press 1, 2, or 3):

If the user enters 1, the qu$z should start as shown below. Th$s part $s fully $mplemented
dur$ng the class.

Choose one of the act$ons above (press 1, 2, or 3): 1

THE QUIZ HAS STARTED

Stup$d answers qu$z (4 quest$ons).

1. What color was Wash$ngton's wh$te horse?


a) Blue
b) Red
c) Wh$te
d) Be$ge
Your answer (a, b, c, d): c
Correct answer!

2. How many green Ch$nese pots are there $n a dozen?


3
a) 10
2
b) -6
1
c) 1
d) 12
Your answer (a, b, c, d):

One m$nor d$fference here $s that the score $s NOT pr$nted after answer$ng each quest$on.
Instead, the total score $s d$splayed after all quest$ons are answered. Total score
corresponds to the total number of correct answers. For example, $f students answers 2
quest$ons correctly, then the score w$ll be 2.

As seen $n the $mage below, at the end of the qu$z, the total score should be pr$nted, and the
menu should be d$splayed to allow the user to cont$nue w$th other act$ons.

4. What $s the f$rst verb $n the Pledge of Alleg$ance?


a) alleg$ance
b) pledge
c) snorkel
d) I

Your answer (a, b, c, d): a


Incorrect. Correct answer was pledge
Your score $s 2

Ava$lable Act$ons:
1) Take the game
2)Produce report
3) Qu$t
Choose one of the act$ons above (press 1, 2, or 3):

2. Produc$ng a Report

The ma$n enhancement to the Qu$z program w$ll be the Report$ng funct$onal$ty. Th$s report
(wh$ch $s prov$ded $n the next page) w$ll be generated based on the contents of follow$ng f$le:
responses.txt. Th$s f$le holds data about the user performance $n each qu$z take, and $t
comes w$th some $n$t$al data. Each l$ne $n th$s f$le corresponds to a s$ngle qu$z attempt. As
the user cont$nues to take the qu$z, the new data should be added as a new l$ne. For example,
$f $n$t$ally there are 5 l$nes of data, and $f the user takes the qu$z 5 t$mes more, the f$le should
conta$n 10 l$nes (or rows).

At each row (correspond$ng to a qu$z attempt), there are 5 p$eces of data separated by a
coma "". The f$rst four p$eces are about the correctness of the user responses (remember
that there are 4 quest$ons $n total), whereas the f$fth (last) p$ece corresponds to the total
user score $n that qu$z attempt. The correct/$ncorrect answer to a quest$on $s $nd$cated w$th 1
or 0. Based on the $mage below, $n the f$rst attempt, the user answered the f$rst quest$on
$ncorrectly, and the rest of the quest$ons correctly. That $s why the data starts w$th 0,1,1,1 as
shown below, and ends w$th 3 (wh$ch $s the total score).
If the user chooses the second opt$on $n the ma$n menu, a report $n the follow$ng format
should be d$splayed to the user. The components of the report are expla$ned on the $mage
below.

Choose one of the act$ons above (press 1, 2, or 3): 2


Your average score $s: 2.6
Quest$on #1: 4 t$mes correct.
Quest$on # 2 : 3 t$mes correct.
Quest$on # 3: 1 t$mes correct.
Quest$on # 4: 5 t$mes correct.
H$ghest success: Quest$on #4.
Lowest success: Quest$on #3.
Ava$lable Act$ons:
. Take the game
. Produce report
. Qu$t
Choose one of the act$ons above (press 1, 2, or 3):

- The average score of all qu$z attempts $s d$splayed at the top.


-Based on all qu$z attempts, the total number of correct answers per each quest$on $s
d$splayed here.
-D$splay the quest$ons w$th the h$ghest and lowest success.
- Ma$n menu $s d$splayed aga$n.

Changes $n f$leHelper.py
You w$ll be prov$ded w$th the f$leHelper.py f$le. However, there $s a sl$ght change $n $t
(d$fferent from the vers$on we used $n the class).
To open a f$le, you need to $nd$cate the purpose: '"': read, 'w': wr$te, or'a': append. Below $s
two example calls to the openF$le funct$on. (BTW, I th$nk you w$ll need to open the f$le w$th
only 'r' and 'a' purposes $n your appl$cat$on. Probably, you should not need 'w' s$nce the text
f$les w$ll be already ava$lable w$th some data).
f$leHandle = fh.openF$le(FILE_PATH, 'I')
f$leHandle = £h.openF$le(RESPONSE_PATH, 'a')

You might also like