Language: Python Program used: PyCharm Interpreter: 3.6.1 at ~/anaconda/bin/pyth
ID: 3871025 • Letter: L
Question
Language: Python
Program used: PyCharm
Interpreter: 3.6.1 at ~/anaconda/bin/python
Purpose: To distinguish between the different parts of functions and function calls. Degree of Difficulty: Easy Below is a program that uses a function to compute the cost of a meal from Jimmy Boy's Catering Company which is priced in dollars. There is a fixed cost of $250 in supplies per meal course and a mandatory 15% gratuity automatically applied to the total. 1def cost of_meal (number of courses, number of_diners, price_per diner): 2 Computes the cost of a fancy meal in dollars number_of_courses: the number of courses in the meal number_of_diners: the number of diners attending price per diner: cost for a single diner to attend in dollars 8 9 10 Returns:total cost of the meal Il n total_cost of_suppliesnumber_of_courses*250 total-diner-cost = number-of-diners * price-per-diner subtotal -total_cost_of_supplies + total_diner_cost gratuity = total-diner-cost * 0.15 return subtotal + gratuity 12 13 14 15 16 17 |# compute the cost of a meal consisting of 3 courses: 181# there are 100 diners and it costs $42.50 per diner 19first mealcost.of meal (3, 100, 42.50) 20 21 # compute the cost of a meal consisting of 5 courses: 22 # there are 40 diners, and it costs $68.14 per diner 23 second_meal-cost of meal (5, 40, 68. 14) Answer the following questions. Refer to line numbers if you find it helpful in your answers. (a) List all the function arguments in this progranm (b) List all the function parameters in this program. (c) List all the variables that are neither arguments or parameters (d) What is the scope of. i. gratuity second meal ii. price_-per_diner (e) How many function definitions are in this program? (f) How many function calls are in this program? (g) What are the values referred to by first_meal and second_meal when the program ends?Explanation / Answer
1. Arguments are the data which we pass to a function having parameters.
Like in this code,
cost_of_meal(3,100,42.50)
cost_of_meal(5,40,68.14)
3,100,42.50,5,40,68.14 these are the data that are passed to function. So, they are the arguments here
2. Parameters hold the values that are passed as an argument in a function. Parameters are variable names present in method definition.
Like in this code-
cost_of_meal(number_of_courses,number_of_diners,price_per_dinner)
number_of_courses
number_of_diners
price_per_dinner
these are parameters
3.All the variables apart from paramters and arguments are-
total_cost_of_supplies
total_diner_cost
subtotal
gratutity
first_meal
second_meal
4. gratutity is a local variable as it is defined inside the function and it is accessible only there.
second_meal is a global variable which is defined outside the function.
price_per_dinner is a paramter in the method definition and is accessible to function only. So, it is a local variable
5. There is only 1 function definition cost_per_meal, function defintion means a function contains a block of code to perform a task.
6.There are 2 function calls to the function cost_per_meal
first_meal=cost_of_meal(3,100,42.50)
second_meal=cost_of_meal(5,40,68.14)
7.when the program ends ,after calculating values will be returned to first_meal and second_meal by cost_of_meal function.
first_meal= 5750
second_meal=4571.94
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.