Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using the function from the previous problem, write a function adventure() which takes in no arguments, and gives the user a sequence of choices, leading

Using the function from the previous problem, write a function adventure() which takes in no arguments, and gives the user a sequence of choices, leading to one of several endings. Since we want this problem to not be impossible to grade, you need to follow a very specific choice structure, namely the one outlined in the flowchart below:image text in transcribed

Each diamond represents a decision, for which you must use your choice function from problem B. Each arrow represents one of the three possible choices for that decision: A, B, or C. Each rounded box represents an ending to the story, which comes in one of two possible types: Good (the user succeeds in some way) or Bad (the user fails). The story itself is entirely up to you, with one exception: you cant use the one in the example below. We will not be grading you based on the storys quality, logic, originality, or grammatical correctness, so if youre lazy and just want to put in empty strings for every single choice, thats fine, but you must follow the choice structure in the flowchart above.

Your function should return the boolean value (not the string) True if the user reached a Good ending, or False if they reached a Bad ending. You can put in a few additional print statements beyond the ones inside the choice function to better explain the story, but this is not required.

Hints:

  • There are two basic ways to do this. You could put in nested if statements for every possible combination of decisions, which will result in some repeated code, since there are multiple paths to decision point 4. Or, you could treat this as a state machine. In particular, if we label each decision as shown below, youll notice that every path through the flowchart passes through states (decisions) in an increasing order (a path may skip some states, but it will never go from a higher numbered state, down to a lower numbered one).

  • You can take advantage of the above by using an extra variable to track what state the user is currently in (what number decision point they are currently at), and changing it every time they make a choice. For each state starting at 1 and ending at 4, check whether the user is in that state, and only give them the respective choice if they are. Since all paths go through states in an increasing numerical order, you only have to check each state once.

    • (If you dont understand the idea behind a state machine, dont worry: its not necessary for this problem or this class, it just makes things a little cleaner)

    • Constraints:

    • Your submitted hw04.py file should have no code outside of function definitions aside from comments.

    • You must use the choice() function from problem B for each decision.

    • There should be no calls to the input() function anywhere in the code for adventure(): choice already takes in user input, so if you need to take in more user input then youre not using choice correctly.

    • Examples (text in bold is returned, text in red is user input, text in italics is printed. Note that because you are required to have a different story than mine, the printed text should not match, but the same sequence of inputs should lead to the same return value):

      >>> adventure()

      You sneak into the dragon's lair, with your comrades Wizard McBlastyFace and Stella the Bard. The dragon is fast asleep.

      A. Tell your team to start stealing things

      B. Tickle the dragon on the nose

      C. Tell your team to prepare for battle

      Choose A, B, or C: B

      The dragon sneezes out a fireball and incinerates you instantly.

      False

A 1 A B Bad Bad A 2 3 Good B Good B 4 A, B Good Bad A 1 A B Bad Bad A 2 3 Good B Good B 4 A, B Good Bad

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Give a counterexample to show that (A + B)-1 A-1 + B-1 in general.

Answered: 1 week ago

Question

What are the qualities to look for in a prospective franchisee?

Answered: 1 week ago

Question

LO1 Identify why performance management is necessary.

Answered: 1 week ago