Instructions for animalQuiz

(produced at 04:19 a.m. UTC on 2024-02-22)

This task is part of project04 which is due at 23:00 EST on 2024-02-20.

You have the option to work with a partner on this task if you wish. Working with a partner requires more work to coordinate schedules, but if you work together and make sure that you are both understanding the code you write, you will make progress faster and learn more.

You can download the starter code for this task using this link.

You can submit this task using this link.

Put all of your work for this task into the file animalQuiz.py
(you will create this file from scratch)

Note that this week, both tasks count separately towards the project credit. In other words, you need to do both of them, instead of just picking one.

What animal are you similar to? In this task, you will write a quiz program that determines your animal based on answers to three questions:

  • Do you like to eat meat?
  • Do you like cold weather?
  • Do you like fuzzy things?

The answers to these three questions determine the animal shown in this table:

like meat? like cold? prefer fuzzy? animal
True True True polar bear
True True False orca
True False True tiger
True False False komodo dragon
False True True yak
False True False clam
False False True bunny
False False False tortoise

Your task is to create the following four functions in a new file named animalQuiz.py:

  1. boolFromResponse - Accepts one parameter (a string) and returns True if that string begins with 'Y' or 'y', returning False in all other cases. The .lower() and .startswith() methods of strings are helpful for this function; using .startswith() is required, and using .lower() is an extra goal. The sample output gives examples of how boolFromResponse should work. boolFromResponse must not call input, because it only looks at its parameter.

  2. boolFromUser - Accepts one parameter (a prompt string) and gathers input from the user using that prompt, before converting that input into a boolean using boolFromResponse, and returning that boolean. The sample output demonstrates how it should workd.

  3. chooseAnimal - Accepts three parameters, each a Boolean: the first indicates whether the user likes meat or not, the second whether they like cold or not, and the third whether they like fuzzy things or not. Based on these three binary decisions, this function returns an animal string based on the table shown above. The sample output demonstrates how it should work. Note that chooseAnimal should not call boolFromUser: it gets boolean values as parameters, and does not itself ask for input. You must use one or more if/else statement(s) to select the appropraite return value.

  4. animalQuiz - Does not accept any parameters. It prompts the user with three yes/no questions, and then displays the animal determined by their answers. See the sample output below for the exact wording you must use. You must use the boolFromUser and chooseAnimal functions within this function, and you may not use input directly (use boolFromUser instead).

Interactive Testing

One way to test your functions is to first run your program in the editor window (to load the function definitions) and then enter sample calls of your functions in the interactive console to test that they work correctly. The behavior of each function should match the provided examples (we have included examples for boolFromResponse, boolFromUser, chooseAnimal, and animalQuiz).

Automatic Testing

Interactive testing can be tedious, and it's easy to make mistakes if you're testing things every time you make one little change. We have provided a file called test_AnimalQuiz.py which will test your functions, although it does not check carefully enough to ensure that they will satisfy all of our extra tests during grading.

You can work from the provided test cases in the starter file as examples, and you are encouraged to use the examples given in this file as the basis for your test cases. We encourage you define your test cases before writing your code, and just comment them out until you're ready to use them, because this will ensure that you have a clear idea of the correct behavior when you start writing each function.

Notes

  • As usual, all of your functions must be documented.
  • Also as usual, you should not waste boxes and you must not waste fruit.
  • The Python string method .lower() returns a lower-case version of the string when called with zero arguments. The .startswith(s) method takes a single string as a parameter, and determines whether the string before the period begins with the string it got as a parameter. These examples show how these methods work. Note that case matters for .startswith.
  • In animalQuiz, you must ask exactly the same questions in the same order. Your printout should match the examples above. You can use this difference checker website to test for any minor differences in your output, and you could also set up tests in optimism for the correct output.

Examples

startswith and lower Examples

These examples demonstrate how the .startswith and .lower methods work.

In []:
'Wendy Wellesley'.startswith('Wend')
Out[]:
True
In []:
'Wendy Wellesley'.startswith('Well')
Out[]:
False
In []:
'Wendy Wellesley'.startswith('W')
Out[]:
True
In []:
'Wendy Wellesley'.startswith('w')
Out[]:
False
In []:
'Wendy Wellesley'.lower()
Out[]:
'wendy wellesley'
In []:
'CS111'.lower()
Out[]:
'cs111'
In []:
'SHOUT!'.lower()
Out[]:
'shout!'
In []:
'the quick brown fox'.lower()
Out[]:
'the quick brown fox'

boolFromResponse Examples

These examples demonstrate how boolFromResponse should work. Note that it doesn't recognize words for 'yes' that don't start with 'y'.

In []:
boolFromResponse('yes')
Out[]:
True
In []:
boolFromResponse('Yes')
Out[]:
True
In []:
boolFromResponse('yup')
Out[]:
True
In []:
boolFromResponse('Yellow')
Out[]:
True
In []:
boolFromResponse('y')
Out[]:
True
In []:
boolFromResponse('No')
Out[]:
False
In []:
boolFromResponse('nope')
Out[]:
False
In []:
boolFromResponse('maybe')
Out[]:
False
In []:
boolFromResponse('affirmative')
Out[]:
False

boolFromUser Examples

These examples demonstrate how boolFromUser should work. Note that unlike boolFromResponse, it gets input from the user instead of via a parameter.

In []:
boolFromUser('Are you happy? ')
Prints
Are you happy? yes
Out[]:
True
In []:
boolFromUser('Are you happy? ')
Prints
Are you happy? NO
Out[]:
False
In []:
boolFromUser('Are you happy? ')
Prints
Are you happy? absolutely!
Out[]:
False

chooseAnimal Examples

These examples demonstrate how chooseAnimal should work. Note that user input is not involved.

In []:
chooseAnimal(False, False, True)
Out[]:
'bunny'
In []:
chooseAnimal(True, False, False)
Out[]:
'komodo dragon'
In []:
chooseAnimal(True, False, True)
Out[]:
'tiger'

animalQuiz Examples

These examples demonstrate how animalQuiz should work. Note that there are no parameters, and the user's answers determine the outcome.

In []:
animalQuiz()
Prints
What animal are you? Let's find out! Do you like to eat meat? Nope Do you like cold weather? yup! Do you like fuzzy things? y Your animal is the yak
In []:
animalQuiz()
Prints
What animal are you? Let's find out! Do you like to eat meat? unsure Do you like cold weather? maybe Do you like fuzzy things? absolutely Your animal is the tortoise

Rubric

Group goals:
 
unknown All functions are documented
Each function you define must include a non-empty documentation string as the very first thing in the function.
 
unknown Do not ignore the results of any fruitful function calls
According to the "Don't waste fruit" principle, every place you call a fruitful function (built-in or custom) you must store the result in a variable, or that function call must be part of a larger expression that uses its return value.
 
unknown Do not create any variables that you never make use of
According to the "Don't waste boxes" principle, every time you create a variable (using = or by defining a parameter for a function) you must also later use that variable as part of another expression. If you need to create a variable that you won't use, it must have the name _, but you should only do this if absolutely necessary.
 
unknown boolFromResponse must return the correct result
The result returned when your boolFromResponse function is run must match the solution result.
 
unknown boolFromResponse must return the correct result
The result returned when your boolFromResponse function is run must match the solution result.
 
unknown boolFromUser must return the correct result
The result returned when your boolFromUser function is run must match the solution result.
 
unknown boolFromUser must return the correct result
The result returned when your boolFromUser function is run must match the solution result.
 
unknown chooseAnimal must return the correct result
The result returned when your chooseAnimal function is run must match the solution result.
 
unknown The output of animalQuiz is approximately correct.
We will run animalQuiz with a variety of inputs, and examine everything that it prints, which should match what the solution code prints.
 
unknown The first animal name mentioned (spelling must be correct) of the output must be correct
the first animal name mentioned (spelling must be correct) of the output must match the solution's output.
 
unknown Define boolFromResponse with 1 parameter
Use def to define boolFromResponse with 1 parameter
 
unknown Do not call input
Within the definition of boolFromResponse with 1 parameter, do not call input.
 
unknown Call .startswith or use indexing
Within the definition of boolFromResponse with 1 parameter, you must either call the .startswith string method or use indexing to check the first letter of the response.
 
unknown Define boolFromResponse with 1 parameter
Use def to define boolFromResponse with 1 parameter
 
unknown Call lower
Within the definition of boolFromResponse with 1 parameter, call lower in at least one place.
 
unknown Do not use a conditional
Within the definition of boolFromResponse with 1 parameter, do not use an if statement (possibly accompanied by an elif or else block).
 
unknown Define boolFromUser with 1 parameter
Use def to define boolFromUser with 1 parameter
 
unknown Call input
Within the definition of boolFromUser with 1 parameter, call input in at least one place.
 
unknown Call boolFromResponse
Within the definition of boolFromUser with 1 parameter, call boolFromResponse in at least one place.
 
unknown Define chooseAnimal with 3 parameters
Use def to define chooseAnimal with 3 parameters
 
unknown Do not call boolFromUser
Within the definition of chooseAnimal with 3 parameters, do not call boolFromUser or boolFromResponse.
 
unknown Use a conditional
Within the definition of chooseAnimal with 3 parameters, use an if statement (possibly accompanied by an elif or else block) in at least one place.
 
unknown Define animalQuiz
Use def to define animalQuiz
 
unknown Do not call input
Within the definition of animalQuiz, do not call input.
 
unknown Call boolFromUser
Within the definition of animalQuiz, call boolFromUser in at least one place.
 
unknown Call chooseAnimal
Within the definition of animalQuiz, call chooseAnimal in at least one place.
 
unknown Define animalQuiz
Use def to define animalQuiz
 
unknown Call boolFromUser
Within the definition of animalQuiz, call boolFromUser in exactly 3 places.
 
unknown Call chooseAnimal
Within the definition of animalQuiz, call chooseAnimal in exactly one place.