Instructions for timeLoop

(produced at 11:27 a.m. UTC on 2021-10-13)

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

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 submit this task using this link.

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

This task will give you practice using while loops, and it allows you to write a different kind of interactive story than the one you wrote for the narrative consequences task.

The idea of a "time loop" is popular in movies and books, and in interactive media, it comes up a lot because many games allow players to retry again and again until they can make a sequence of correct choices. In this task, you will create your own time loop, where if the player makes the wrong choice, they'll have to start over at the beginning, but if they make the right choices they can reach the end of the story.

Note: if you don't want to spend time writing a story for this task, you don't have to. You're free to copy the story text shown in the examples, or just make up meaningless text to use, as long as your functions have the required behavior in terms reaching an ending or not.

There are only two required functions, although you may use more:

Once you have written both of these functions and verified that they are working as described above, you are done with this task.

Notes

  • You will create a new file from scratch for this task; there is no provided starter code.
  • As usual, you must document every function you write.
  • Also as usual, you must not waste fruit and you must not waste boxes.
  • It may be helpful to define choice1 and choice2 functions which return Boolean values, like you did in the narrative consequences task. This isn't required, however, and if you prefer you can simply use letUserPick directly within the timeLoop function.
  • If you want to, you may include up to 5 choices in your loop, as long as it's still the case that choosing '1' at each of them will end the loop, while choosing '3' at each of them will continue indefinitely. If you do add extra choices, do not use more than 5 choices in total, or our grading scripts will fail.
  • You are not required to do any testing for this task, but it isn't a bad idea to write some tests for your letUserPick function. We've provided a copy of optimism.py in the starter code in case you want to do this. Testing timeLoop is also possible, but more complicated. If you do write tests, putting them in a function named test is one way to organize them, and remmeber to call restoreOutput and restoreInput when you're done with testing.

Examples

letUserPick Examples

These examples show how letUserPick works. Note that it always returns an integer, and any input other than exactly '1', '2', or '3' will result in another iteration of the loop where input is requested. For this function, your output should match this example exactly.

In []:
letUserPick('Option 1', 'Option 2', 'Option 3')
Prints
What do you want to do? 1. Option 1 2. Option 2 3. Option 3 Enter your choice (1, 2, or 3): 1
Out[]:
1
In []:
letUserPick('Persuade', 'Intimidate', 'Beguile')
Prints
What do you want to do? 1. Persuade 2. Intimidate 3. Beguile Enter your choice (1, 2, or 3): 2
Out[]:
2
In []:
letUserPick('Follow them', 'Wait for Ian', 'Flip the table')
Prints
What do you want to do? 1. Follow them 2. Wait for Ian 3. Flip the table Enter your choice (1, 2, or 3): flip it 'flip it' is not a valid option. Enter just a single digit ('1', '2', or '3'). What do you want to do? 1. Follow them 2. Wait for Ian 3. Flip the table Enter your choice (1, 2, or 3): no really, flip it! 'no really, flip it!' is not a valid option. Enter just a single digit ('1', '2', or '3'). What do you want to do? 1. Follow them 2. Wait for Ian 3. Flip the table Enter your choice (1, 2, or 3): 3
Out[]:
3

timeLoop Example

This example shows how timeLoop puts together the other functions defined so far to tell an interactive story. Your text won't be the same, but the way that your whole story responds to different input combinations is important. In particular, if '1' is chosen at each choice, the story must end, while if '3' is chosen at each choice, they story must continue indefinitely.

In []:
timeLoop()
Prints
You approach the kitchen sink, ready to get your hands dirty and your dishes clean! You're going to have to wash these dishes carefully if you want to get this chore done with. First, you decide to tackle the plates and glasses. What do you want to do? 1. Scrub them with soapy water and a sponge. 2. Wipe them gently with a damp cloth. 3. Use some fine steel wool to scrub them vigorously. Enter your choice (1, 2, or 3): 1 --- You scrub the plates and glasses with a sponge, washing away the remnants of the meal. By the time you're done, they're shiny and clean. You take a short break, and then get back to it. --- All that's left is the big stainless-steel pan, but it's got food crusted onto the sides and bottom, and a bit at the bottom is even burned on. What do you want to do? 1. Use some fine steel wool to scrub it vigorously. 2. Scrub it with soapy water and a sponge. 3. Pour in some vinegar and let it sit overnight. Enter your choice (1, 2, or 3): 1 --- You rinse out most of the mess and then scrub the more stubborn bits with steel wool, tiring your arm but getting the pot nice and clean again. Without too much trouble, you managed to wash the dishes! A relaxing evening lies ahead of you. --- The End ---
In []:
timeLoop()
Prints
You approach the kitchen sink, ready to get your hands dirty and your dishes clean! You're going to have to wash these dishes carefully if you want to get this chore done with. First, you decide to tackle the plates and glasses. What do you want to do? 1. Scrub them with soapy water and a sponge. 2. Wipe them gently with a damp cloth. 3. Use some fine steel wool to scrub them vigorously. Enter your choice (1, 2, or 3): 1 --- You scrub the plates and glasses with a sponge, washing away the remnants of the meal. By the time you're done, they're shiny and clean. You take a short break, and then get back to it. --- All that's left is the big stainless-steel pan, but it's got food crusted onto the sides and bottom, and a bit at the bottom is even burned on. What do you want to do? 1. Use some fine steel wool to scrub it vigorously. 2. Scrub it with soapy water and a sponge. 3. Pour in some vinegar and let it sit overnight. Enter your choice (1, 2, or 3): 2 --- You scrub the pot with a sponge, but you aren't making much headway, and your sponge is getting crusted with grime faster than the pot is getting clean! Perhaps that wasn't the wisest decision? You got the dishes clean, but the pot needs work. Let's try that again... --- You approach the kitchen sink, ready to get your hands dirty and your dishes clean! You're going to have to wash these dishes carefully if you want to get this chore done with. First, you decide to tackle the plates and glasses. What do you want to do? 1. Scrub them with soapy water and a sponge. 2. Wipe them gently with a damp cloth. 3. Use some fine steel wool to scrub them vigorously. Enter your choice (1, 2, or 3): 1 --- You scrub the plates and glasses with a sponge, washing away the remnants of the meal. By the time you're done, they're shiny and clean. You take a short break, and then get back to it. --- All that's left is the big stainless-steel pan, but it's got food crusted onto the sides and bottom, and a bit at the bottom is even burned on. What do you want to do? 1. Use some fine steel wool to scrub it vigorously. 2. Scrub it with soapy water and a sponge. 3. Pour in some vinegar and let it sit overnight. Enter your choice (1, 2, or 3): 3 --- Looking at the mess, you realize that it isn't going to come off easily tonight, and you decide to leave it for the morning. You pour in some vinegar to soak off the burned bits, and let it be for now. In the morning, it'll be easy to wash out the rest. Without too much trouble, you managed to wash the dishes! A relaxing evening lies ahead of you. --- The End ---
In []:
timeLoop()
Prints
You approach the kitchen sink, ready to get your hands dirty and your dishes clean! You're going to have to wash these dishes carefully if you want to get this chore done with. First, you decide to tackle the plates and glasses. What do you want to do? 1. Scrub them with soapy water and a sponge. 2. Wipe them gently with a damp cloth. 3. Use some fine steel wool to scrub them vigorously. Enter your choice (1, 2, or 3): 3 --- Putting your elbow into it, you apply the steel wool to the plates and glasses. A horrible grating sound echoes through the kitchen, as you grind their surfaces into a mess of scratches! Perhaps that wasn't the best decision? You take a short break, and then get back to it. --- All that's left is the big stainless-steel pan, but it's got food crusted onto the sides and bottom, and a bit at the bottom is even burned on. What do you want to do? 1. Use some fine steel wool to scrub it vigorously. 2. Scrub it with soapy water and a sponge. 3. Pour in some vinegar and let it sit overnight. Enter your choice (1, 2, or 3): 3 --- Looking at the mess, you realize that it isn't going to come off easily tonight, and you decide to leave it for the morning. You pour in some vinegar to soak off the burned bits, and let it be for now. In the morning, it'll be easy to wash out the rest. The pot is fine, but the dishes are a mess. Let's try that again... --- You approach the kitchen sink, ready to get your hands dirty and your dishes clean! You're going to have to wash these dishes carefully if you want to get this chore done with. First, you decide to tackle the plates and glasses. What do you want to do? 1. Scrub them with soapy water and a sponge. 2. Wipe them gently with a damp cloth. 3. Use some fine steel wool to scrub them vigorously. Enter your choice (1, 2, or 3): 3 --- Putting your elbow into it, you apply the steel wool to the plates and glasses. A horrible grating sound echoes through the kitchen, as you grind their surfaces into a mess of scratches! Perhaps that wasn't the best decision? You take a short break, and then get back to it. --- All that's left is the big stainless-steel pan, but it's got food crusted onto the sides and bottom, and a bit at the bottom is even burned on. What do you want to do? 1. Use some fine steel wool to scrub it vigorously. 2. Scrub it with soapy water and a sponge. 3. Pour in some vinegar and let it sit overnight. Enter your choice (1, 2, or 3): 3 --- Looking at the mess, you realize that it isn't going to come off easily tonight, and you decide to leave it for the morning. You pour in some vinegar to soak off the burned bits, and let it be for now. In the morning, it'll be easy to wash out the rest. The pot is fine, but the dishes are a mess. Let's try that again... --- You approach the kitchen sink, ready to get your hands dirty and your dishes clean! You're going to have to wash these dishes carefully if you want to get this chore done with. First, you decide to tackle the plates and glasses. What do you want to do? 1. Scrub them with soapy water and a sponge. 2. Wipe them gently with a damp cloth. 3. Use some fine steel wool to scrub them vigorously. Enter your choice (1, 2, or 3): 1 --- You scrub the plates and glasses with a sponge, washing away the remnants of the meal. By the time you're done, they're shiny and clean. You take a short break, and then get back to it. --- All that's left is the big stainless-steel pan, but it's got food crusted onto the sides and bottom, and a bit at the bottom is even burned on. What do you want to do? 1. Use some fine steel wool to scrub it vigorously. 2. Scrub it with soapy water and a sponge. 3. Pour in some vinegar and let it sit overnight. Enter your choice (1, 2, or 3): 1 --- You rinse out most of the mess and then scrub the more stubborn bits with steel wool, tiring your arm but getting the pot nice and clean again. It took some doing, but you managed to wash the dishes! A relaxing evening lies ahead of you. --- The End ---

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 letUserPick with 3 parameters
Use def to define letUserPick with 3 parameters
 
unknown Use a loop
Within the definition of letUserPick with 3 parameters, use a while loop in exactly one place.
 
unknown Call print
Within the loop within the definition of letUserPick with 3 parameters, call print in at least once place.
 
unknown Call input
Within the loop within the definition of letUserPick with 3 parameters, call input in at least once place.
 
unknown Use a conditional
Within the definition of letUserPick with 3 parameters, use an if statement (possibly accompanied by an elif or else block) in at least once place.
 
unknown Use a return statement
Within the definition of letUserPick with 3 parameters, use return _ in at least once place.
 
unknown Define timeLoop with 0 parameters
Use def to define timeLoop with 0 parameters
 
unknown Use a loop
Within the definition of timeLoop with 0 parameters, use a while loop in exactly one place.
 
unknown Call letUserPick
Within the loop within the definition of timeLoop with 0 parameters, call letUserPick 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 letUserPick with 3 parameters
Use def to define letUserPick with 3 parameters
 
unknown Don't use input outside your loop
Within the definition of letUserPick with 3 parameters, do not use input anywhere outside of your while loop.
 
unknown Define timeLoop with 0 parameters
Use def to define timeLoop with 0 parameters
 
unknown Use a loop
Within the definition of timeLoop with 0 parameters, use a while loop in exactly one place.
 
unknown Use a conditional
Within the loop within the definition of timeLoop with 0 parameters, use an if statement (possibly accompanied by an elif or else block) in at least once place.
 
unknown Do not call input
Within the definition of timeLoop with 0 parameters, do not call input.
 
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 letUserPick returns the correct result
The result returned when your letUserPick 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 letUserPick returns the correct result
The result returned when your letUserPick 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 timeLoop eventually ends when option 1 is chosen
If the user continuously chooses option 1, the time loop must end after no more than 5 choices. It's okay if there are fewer choices. We will check for the text 'The End' (capitalization matters).
 
unknown timeLoop doesn't end when option 3 is chosen
If the user continuously chooses option 3, the time loop must never end, no matter how many times the user chooses that option. We will check for the text 'The End' (capitalization matters).
 
unknown letUserPick prints the correct output
The output printed when your letUserPick function is run must match the solution output.
 
unknown Extra goals
Complete all extra goals in addition to the core goals for a perfect score.
 
unknown timeLoop handles other inputs
When '1' is chosen at least 10 times, timeLoop should end, even if other inputs were also provided beforehand, including invalid inputs. If only invalid inputs and/or '3's are provided, it should not end. We will check for an out-of-input error.
 
unknown letUserPick prints the correct output
The output printed when your letUserPick function is run must match the solution output.