Lab 4: Automatic Quiz Details

Continuing with the divide, solve, combine theme, we will break this program into individual functions. Note that these are suggestions, there are many different ways to divide the quiz into parts.

Part A

In the lab04/conditionals.py file, you are provided with the function called askUserForAnswer which returns the integer corresponding to the user's choice.

Test this function in the Python console so you understand what it does.

In[]: askUserForAnswer()

Select 1, 2 or 3: 1
Out[]: 1

In[]: askUserForAnswer()

Select 1, 2 or 3: 2
Out[]: 2

Task B

Now, write a function called firstQuestion() that prints a question followed by three answer options, e.g.

In[]: firstQuestion()

Which food do you like the most?
1: artichokes
2: lettuce
3: kimchi

You can come up with your own questions/answers, just associate the #1 option with earth, the #2 option with water, and the #3 option with fire.

Note that this function does not need to prompt the user for their input, it simply needs to print the question and possible answers.

Once firstQuestion() is written and tested, write two additional question/answer functions (secondQuestion, and thirdQuestion).

Part C

Write a function called determineElement that accepts three integers as parameters and returns a calculated element as a String (earth, water, fire).

In[]: determineElement(1, 1, 1)
Out[]: 'earth'

In[]: determineElement(2, 2, 2)
Out[]: 'water'

In[]: determineElement(1, 2, 3)
Out[]: 'water'

In[]: determineElement(3, 3, 3)
Out[]: 'fire'

It's up to you to design the formula for how the elements are chosen. In the above example, we had programmed it so that if they chose 1 for all the answers, they were earth. If they chose 3 for all the answers they were fire. If they chose a mixture of 1,2,3 they were water.

But again, the formula is up to you to design as you like. Have fun with it!

Part D

Finally, write a function called runQuiz that does the following:

When you're done, test your quiz to make sure it works as expected.

Table of Contents