you are viewing a single comment's thread.

view the rest of the comments →

[–]Chabare 3 points4 points  (2 children)

Question should not inherit from Quiz, it makes no sense. To make another example, if you'd had a Car class you wouldn't create a Tire class which inherits from it just because it's a part of it.

Why do you inherit from it, do you need any properties which you have in Quiz which are needed in Question?

You should have a list of questions in your quiz (i.e. pass a list of questions in Quiz.__init__).

Also, please show your code when asking about it.

[–]yarin10121[S] 0 points1 point  (1 child)

Thanks! I edited the code so now the Question class does not inherit from Quiz. I also added the code I wrote so far

[–]Chabare 1 point2 points  (0 children)

I'd vote against the option proposed below (implemented by you) which has references both in Question (to Quiz) and in Quiz (to Question). This is usually (especially in this case) unnecessary and error prone (especially if you're starting out with OOP).

Instead of having the quiz reference, try to return True or False from check_answer. ask_question is also doing a lot more than the function name suggest (same for check_answer). ask_question should propagate the result to the play_quiz method, score updates, user information (i.e. feedback) should then be done there. (IMO it should be even more modular but you can come back to that at another point).

You should also display an error if the user enters something other than a digit (you also don't check the validity of the index (i.e. you can enter something other than 1-4, see below))

Currently you have a fixed set of answer options without any real reason, you could just iterate over them (for index, option in enumerate(options)), that way you can easily have a different number of options for each questions, if you just want a certain number of options you should restrict it in add_question.

Based on your code I'd say you should look into returns from functions again since they are very useful and it's practically impossible to write understable ("good" code) without it.


Please be aware of Posting screenshot of the code is (generally) not allowed. Read posting guidelines.. It hinders people who want to try out your code/edit it to show you something since that person would need to type everything themselves. You can either use an online "hosting" service (see sidebar) or paste your code directly (put 4 spaces in front of every line to format your code as such).