This task is part of project03 which is due at 23:00 EST on 2026-09-28.
This is an individual task that you must do on your own.
You can download the starter code for this task using this link.
See how to 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)
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:
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 six functions in a new file named
animalQuiz.py:
boolFromResponse - Takes
one argument (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.
boolFromUser - Takes one
argument (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
work.
chooseAnimalIfStm1 - Takes three
arguments, 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 chooseAnimalIfStm1 should not call
boolFromUser:
it gets boolean values as parameters, and does not itself ask for
input. Furthermore, the body of this function must satisfy numerous implementation constraints:
if, has 6 elifs,
and ends with an else;return statements;if or elif
must use the logical operators and and or
apropriately to reflect the logic of one row of the above table.== or !=
or the boolean literals True or False.
chooseAnimalIfStm2 -
chooseAnimalIfStm2 is just an alternative implementation of
chooseAnimalIfStm1 that has exactly the same behavior
and implementation constraints as
chooseAnimalIfStm1 except that it must use exactly 7
if/else statements, without using the elif
keyword.
chooseAnimalIfExp -
chooseAnimalIfExp is just an alternative implementation of
chooseAnimalIfStm1 and chooseAnimalIfStm2
that has exactly the same behavior as these two functions, but
whose implementation must use exactly 7 if/else expressions
(not statements), only a single return statement,
and no occurrences of and, not/code>,
==/code>, or !=.
animalQuiz - Takes zero arguments.
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
chooseAnimalIfStm1
functions within this function, and you may not use input
directly (use
boolFromUser instead).
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,
chooseAnimalIfStm1, and
animalQuiz).
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.
.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.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.startswith and lower Examples
These examples demonstrate how the .startswith and .lower methods work.
In []:Out[]:'Wendy Wellesley'.startswith('Wend')In []:TrueOut[]:'Wendy Wellesley'.startswith('Well')In []:FalseOut[]:'Wendy Wellesley'.startswith('W')In []:TrueOut[]:'Wendy Wellesley'.startswith('w')In []:FalseOut[]:'Wendy Wellesley'.lower()In []:'wendy wellesley'Out[]:'CS111'.lower()In []:'cs111'Out[]:'SHOUT!'.lower()In []:'shout!'Out[]:'the quick brown fox'.lower()'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 []:Out[]:boolFromResponse('yes')In []:TrueOut[]:boolFromResponse('Yes')In []:TrueOut[]:boolFromResponse('yup')In []:TrueOut[]:boolFromResponse('Yellow')In []:TrueOut[]:boolFromResponse('y')In []:TrueOut[]:boolFromResponse('No')In []:FalseOut[]:boolFromResponse('nope')In []:FalseOut[]:boolFromResponse('maybe')In []:FalseOut[]:boolFromResponse('affirmative')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 []:PrintsboolFromUser('Are you sad? ')Are you sad? yesOut[]:In []:TruePrintsboolFromUser('Are you happy? ')Are you happy? NOOut[]:In []:FalsePrintsboolFromUser('Are you mad? ')Are you mad? absolutely!Out[]:False
chooseAnimalIfStm1 Examples
These examples demonstrate how chooseAnimalIfStm1 should work. Note that user input is not involved.
In []:Out[]:chooseAnimalIfStm1(False, False, True)In []:'bunny'Out[]:chooseAnimalIfStm1(True, False, False)In []:'komodo dragon'Out[]:chooseAnimalIfStm1(True, False, True)'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 []:PrintsanimalQuiz()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 yakIn []:PrintsanimalQuiz()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
= 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.boolFromResponse must return the correct result
boolFromResponse function is run must match the solution result.boolFromResponse must return the correct result
boolFromResponse function is run must match the solution result.boolFromUser must return the correct result
boolFromUser function is run must match the solution result.boolFromUser must return the correct result
boolFromUser function is run must match the solution result.chooseAnimalIfStm1 must return the correct result
chooseAnimalIfStm1 function is run must match the solution result.chooseAnimalIfStm2 must return the correct result
chooseAnimalIfStm2 function is run must match the solution result.chooseAnimalIfExp must return the correct result
chooseAnimalIfExp function is run must match the solution result.animalQuiz is approximately correct.
animalQuiz with a variety of inputs, and examine everything that it prints, which should match what the solution code prints.boolFromResponse with 1 parameter
def to define boolFromResponse with 1 parameterlower
boolFromResponse with 1 parameter, call lower in at least one place.boolFromResponse with 1 parameter, do not use an if statement (possibly accompanied by an elif or else block).boolFromResponse with 1 parameter
def to define boolFromResponse with 1 parameterinput
boolFromResponse with 1 parameter, do not call input..startswith or use indexing
boolFromResponse with 1 parameter, you must either call the .startswith string method or use indexing to check the first letter of the response.boolFromUser with 1 parameter
def to define boolFromUser with 1 parameterinput
boolFromUser with 1 parameter, call input in at least one place.boolFromResponse
boolFromUser with 1 parameter, call boolFromResponse in at least one place.chooseAnimalIfStm1 with 3 parameters
def to define chooseAnimalIfStm1 with 3 parametersboolFromUser
chooseAnimalIfStm1 with 3 parameters, do not call boolFromUser or boolFromResponse.
chooseAnimalIfStm1 with 3 parameters, use a chained conditional that begins with an if, has 6 elifs,
and ends with an else
chooseAnimalIfStm1 with 3 parameters, use exactly 8 return statements.
chooseAnimalIfStm1 with 3 parameters, each tests expression in an if or elif must use (potentially multiple occurrences of) the and operator and possibly the not operator.
chooseAnimalIfStm1 with 3 parameters, boolean test expressions in an if or elif must not use the comparison operators ==
or !=, nor the boolean literals True or False.
chooseAnimalIfStm2 with 3 parameters
def to define chooseAnimalIfStm2 with 3 parametersboolFromUser
chooseAnimalIfStm2 with 3 parameters, do not call boolFromUser or boolFromResponse.chooseAnimalIfStm2 with 3 parameters, use an if statement (possibly accompanied by an elif or else block) in at least one place.animalQuiz
def to define animalQuizboolFromUser
animalQuiz, call boolFromUser in exactly 3 places.chooseAnimalIfStm1
animalQuiz, call chooseAnimalIfStm1 in exactly one place.animalQuiz
def to define animalQuizinput
animalQuiz, do not call input.boolFromUser
animalQuiz, call boolFromUser in at least one place.chooseAnimalIfStm1
animalQuiz, call chooseAnimalIfStm1 in at least one place.