Adding A Menu
Adding A Menu
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.
If the user enters 1, the qu$z should start as shown below. Th$s part $s fully $mplemented
dur$ng the class.
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.
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.
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')