[Tutor] Help on Assignments - trivia game
Alan Gauld
alan.gauld at yahoo.co.uk
Sat Jul 30 19:11:40 EDT 2016
On 30/07/16 16:28, Justin Korn via Tutor wrote:
> trivia_game.py
> import sys
> import random
> import Question.py
You do not include the .py extension in an import
statement. It should read
import Question
Also by convention modules use lowercase names.
> questions = [
> Question("How many states start with the letter M", 3, ["6", "7", "8", "9"]),
You are trying to instantiate a Question object but it is (presumably)
defined in the question.py class which you import. If so you need to
prefix it with the module name like so
Question.Question(...)
> Question("What is the area of a right triagle with a hypotenuse of 10 and an altitude of 8", 1, ["24", "40", "48", "80"]),
> Question("Which physics quantity is not a vector", 4, ["Acceleration", "Momentum", "Torque", "Work"]),
List indices start from zero so your highest index should be 3.
Assuming you intend to use the '4' as an index to the correct answer?
> Question("Who won super bowl 44", 1, ["New Orleans Saints", "Pittsburgh Steelers", "Minnesota Vikings", "Indianapolis Colts"])
> ]
>
>
> random.shuffle(questions) # Randomize the order of the questions
>
> for question in questions:
> question.ask()
>
> Question.py
???
I'm expecting a class definition here with at least
__init__() and ask() methods. And it needs to store
the question, possible answers and correct answer
somewhere too?
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list