Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Documentation: Use the following template for EVERY function that you write. The docstring below should be placed inside of the function, just after the function

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Documentation: Use the following template for EVERY function that you write. The docstring below should be placed inside of the function, just after the function signature. Purpose: Parameter(s): Return Value: Problem A. (10 points) Shopping for Donuts Donuts are a delicious baked good that can be enjoyed individually or bought in bulk for Friday morning at the office. Many bakeries charge a different price per donut depending on the quantity purchased. Generally, a larger order means a lower price per donut. At one particular bakery, the prices follow this pattern: This bakery also runs a customer loyalty program. If a customer is a registered member, they receive a 5 e discount per donut. So, for example, if the customer purchases 6 donuts, and are a member of the bakery, the cost per donut would be 80e normally (since the order is between 2 and 9 ) donuts, but would be lowered to 75 e per donut due to the member discount, for a totil cost of: 6(805)6(75c)4506 Write a function called donut_costs(num_donuts, member) that takes in two parameters: - num donuts, an integer representing how many donuts the customer is purchasing. - member, a boolean value that is True if the customer is a member of the bakery, or False if they are not. Using these parameters and the information in the chart above, calculate and return the total cost in cents of the customer's order as an integer. Hints: - You may assume that the customer will order at least one donut. Testing: For this problem, we'll only provide one test case. This is because you'll need to write your own test cases using an if _name _ = _ main_ block. Recall that an if _name _ = - main _ block is suitable for test cases because code inside only runs when the file is executed directly, and not when it's imported from another file. Your test cases need to meet the following requirements: - Add enough test cases to reach statement coverage: that is, every line of code in your donut_costs function needs to be run by at least one of the test cases. - At least two test cases must cover edge cases - which in this case means that the number of donuts must be on the border between two of the price ranges above. - Each test case should be formatted as shown below, with the expected value placed in a comment after the function call: \[ \text { 1f _- } \begin{array}{l} \text { name } \\ \text { print(donut_costs(6, True))) H Should output } 450 \end{array} \] Problem B. (10 points) Text Adventure Choice Some of the earliest computer games developed were Interactive Fiction games, in which the user's environment is described in text, and the user makes choices using text commands. In this problem and the next one, we'll be developing a very simple text-based adventure game. Every choice in this game will have exactly three options, so we can write a function that works for any of them. Write a function choose_three(text, optionA, options, optionc), that takes in four parameters: - text is a string representing a prompt in a text adventure game - optionA, optionB, and optionC are strings representing the three possible options. The function should print out the prompt, and then print out the options (label them with A., B., and C.). Next, use the input function to prompt the user to choose A,B, or C. If the user does not choose one of ' A', ' B ', or ' C ', then the function should print out ' Invalid option, try again. ', and prompt the user to choose again. Then the function should return (not print) the one character string that represents the user's choice: ' A ', ' B ', or ' C '. See the examples on the next page for an idea of how to format the printing and input functions: you don't have to match it exactly but it should be roughly the same (you do have to match the return exactly though: returning lowercase ' a ', ' b ', or ' c ' will case you to fail test cases). You are welcome to add test cases for this finction to the if _name _ = - main _. block, but this is not required. You don't need a separate block, just put everything in one block at the end of the file. Hint: - When calling functions that return something like input, you gencrally want to assign the result to a variable so that you can access it later var = Input () - When calling functions that return something like input, you generally want to assign the result to a variable so that you can access it later: var = input () - You do need to make sure your variable names describe the value they represent, so don't actually use var as a variable name in this problem. Constraints: - You are required to use a while loop to accomplish this. - Your while loop must use a condition that enforces the idea of "keep looping until the user chooses A, B, or C - that is, you can't just use a while True loop and get out of it early using a return statement. - Any test cases, or other code in your hw04.py file that's outside of the function definitions, must be placed in the if _name _ = _main 'block, or you are likely to crash the Gradescope testing scripts. Examples (text in bold is returned, text in red is user input, text in italics is printed): choose_three( "You have no idea how to approach this problem. ", "Send an email to the TAs", "Go to office hours", "Post the problem online, there's no way I'11 be caught") You have no idea how to approach this problem. A. Send an email to the TAs B. Go to office hours C. Post the problem online, there's no way I ' 21 be caught choose A,B, or C: A ' A ' > choose.three( "You must decide the fate of the galaxy. ", "Destroy the robots", "Contral the robots", "Merge with the robots?") You must decide the fate of the gataxy. A. Destroy the robots "Control the robots", "Merge with the robots?") You must decide the fate of the galaxy. A. Destroy the robots B. Control the robots C. Merge with the robots? Choose A,B, or C:B Invalid option, try again. Choose A,B, or C: C ' C ' > choose_three("Choose a house.", "Black Eagles", "Slytherin", "Lannister") Choose a house. A. Black Eagles B. Slytherin c. Lannister Choose A, B, or C: Black Eagtes Invalid option, try again. Choose A,B, or C:AB Invalid option, try again. Choose A,B, or C: D Invatid option, try again. Choose A,B, or C : B 'B

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions