Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 1 (Based on an exercise by Cay Horstmann and Rance Necaise) Calculating the tip when you go to a restaurant is not difficult, but

image text in transcribed

image text in transcribed

Exercise 1 (Based on an exercise by Cay Horstmann and Rance Necaise) Calculating the tip when you go to a restaurant is not difficult, but a restaurant wants to suggest a tip based on the diners' satisfaction with the level of service they receive. In this exercise, you'll use the function design recipe from Chapter 3 of Practical Programming to develop a function named tip. The function has two parameters. The first argument is the cost of the meal. The second parameter is satisfaction level. (Use these ratings: 1 = Totally satisfied, 2 = Somewhat satisfied, 3 = Dissatisfied). The function returns the amount of the tip, calculated as follows: If the diners are totally satisfied, calculate a 20% tip. If the diners are somewhat satisfied, calculate a 15% tip. If the diners are dissatisfied, calculate a 5% tip. . Step 1: Launch Wing 101. Create a new editor window and save it. Use lab5ex1.py as the file name. Step 2: Type this function header and empty docstring. def tip(): II II II Step 3 (Examples): In the docstring, type two or three example function calls and return values. Use a calculator to determine the value the function should return for a given set of arguments. Step 4 (Header): Add parameters (use descriptive names) and type annotations to the function header. Step 5 (Description): In the docstring, write a sentence or two that describes what the function does (but not how it does it). Mention the parameters in your description and describe the return value. Remember to describe any preconditions on the parameter values. Step 6 (Body): Design and code the function body. Hint: you don't need to use the Boolean operators (and, or and not). Save the code, then click Run. Correct any syntax errors. Step 7 (Test): Use the Python shell to test your function (use the docstring examples). After you've finished testing, close the editor window for lab5ex1.py

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_2

Step: 3

blur-text-image_3

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

Databases Organizing Information Digital And Information Literacy

Authors: Greg Roza

1st Edition

1448805929, 978-1448805921

More Books

Students also viewed these Databases questions