Instructions for animalQuiz

(produced at 16:57 UTC on 2021-10-04)

This task is part of ps04 which is due at 23:59 EDT on 2021-10-05.

This is an individual task.

You can submit this task using this link.

Put all of your work for this task into the file animalQuiz.py
(which is provided among the starter files)

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 flesh out the following four function definitions in the provided 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.

  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.

  4. animalQuiz - Does not accept any parameters. 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.

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. The optimism library is provided so that you can establish automated tests.

In the initial version of this task, a certain number of expectations were required, but that requirement has been dropped.

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 must 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

 
unknown Style Requirements
How your code is written.
 
unknown Core goals
Complete all core goals for core credit. Get partial credit for completing at least half, and more partial credit for completing at least 90%.
 
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 Procedure Requirements
What code you use to solve the problem.
 
unknown Core goals
Complete all core goals for core credit. Get partial credit for completing at least half, and more partial credit for completing at least 90%.
 
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 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 once place.
 
unknown Call boolFromResponse
Within the definition of boolFromUser with 1 parameter, call boolFromResponse in at least once 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 once 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 once place.
 
unknown Call chooseAnimal
Within the definition of animalQuiz, call chooseAnimal in at least once place.
 
unknown Extra goals
Complete all extra goals in addition to the core goals for a perfect score.
 
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 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 once 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 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.
 
unknown Product Requirements
Your code's result values.
 
unknown Core goals
Complete all core goals for core credit. Get partial credit for completing at least half, and more partial credit for completing at least 90%.
 
unknown boolFromResponse returns the correct result
The result returned when your boolFromResponse function is run must match the solution result.
 
unknown boolFromUser returns the correct result
The result returned when your boolFromUser function is run must match the solution result.
 
unknown chooseAnimal returns the correct result
The result returned when your chooseAnimal function is run must match the solution result.
 
unknown Extra goals
Complete all extra goals in addition to the core goals for a perfect score.
 
unknown boolFromResponse returns the correct result
The result returned when your boolFromResponse function is run must match the solution result.
 
unknown boolFromUser returns the correct result
The result returned when your boolFromUser function is run must match the solution result.
 
unknown Behavior Requirements
What your code does from the user's perspective.
 
unknown Core goals
Complete all core goals for core credit. Get partial credit for completing at least half, and more partial credit for completing at least 90%.
 
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.