Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Below is a program that uses a function to compute the cost of leaving dogs at J

ID: 3878598 • Letter: B

Question

Below is a program that uses a function to compute the cost of leaving dogs at Joey's Doggy Day Care There is cost per dog that is charged daily 1 def day_care cost (number of_dogs, number.of days, price-per_dog): 3 Computes the total cost of a stay at Doggy Day Care 4 6 8 number_of dogs the number of dogs number_of days duration of stay in days price per dog cost for a single dog in dollars Returns total cost of the stay 10 12 13 daily-dog-cost = number-of-dogs * price-per-dog total-cost = daily-dog-cost * number-of-days return total_cost 15 |# compute the cost of a stay for 3 dogs 16|# staying 7 days at a rate of $49.50 per dog 17 first stay day care_cost (3, 7, 49.50) 18 19|# compute the cost of a stay for 10 dogs 20 |# staying 3 days at a rate of $19.75 per dog 211 second-stay day-care-cost (10, 3, 19.75) = Answer the following questions. Refer to line numbers if you find it helpful in your answers. (a) List all of the function arguments in this program. (b) List all of the function parameters in this program. (c) List all of the variables that are neither arguments or parameters. (d) What is the scope of i. daily_dog_cost ii. number_of_days ii. first stay (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_stay and second stay when the program ends?

Explanation / Answer

1) Function arguments: 6

Arguments are the values passed to method while calling it.

Here we have at line 17

day_care_cost(3,7,49.50)

Arguments 3 : 3,7,49.50

Then at line 21

day_care_cost(10,3,19.75)

Arguments 3 : 10,3,19.75

Total 6 arguments

2) Function parameters

Parameters are the one at method definition

We have only one function here at line 1

day_care_cost(number_of_dogs_number_of_das,price_per_dog)

So total parameters is 3

3) Variables

first_stay which is holding value returned from function at line 17, this is neither passed as argument to function or defined as parameter in function definition.

second_stay which is holding value returned from function at line 21, this is neither passed as argument to function or defined as parameter in function definition.

daily_dog_cost : inside function body at line 11 which is holding value of an expression

total_cost : inside body function at line 12 holding value of an expression.

d) Scope of:

daily_dog_cost - Inside function body as it is defined inside it.

number_of_days - Inside function body as its the parameter of function and used inside it

first_stay - Its scope is program as its defined in main body not inside any function.

e) Number of function definition: 1

We just have one function definition day_care_cost.

f) Number of function calls -

We are calling function day_care_cost at line 17 and line 21

g)

first_stay= day_care_cost(3,7,49..50)

Here by calling function with these value

number_of_dogs = 3

number_of_days = 7

price_per_dog = 49.50

Now inside function body

daily_dog_cost = number_of_dogs * price_per_dog

daily_dog_cost = 3*49.50

daily_dog_cost = 148.50

total_cost = daily_dog_cost * number_of_days

total_cost = 148.50 * 7

total_cost = 1039.50

Hence value of first_stay = 1039.50

second_stay= day_care_cost(10,3,19.50)

Here by calling function with these value

number_of_dogs = 10

number_of_days = 3

price_per_dog = 19.50

Now inside function body

daily_dog_cost = number_of_dogs * price_per_dog

daily_dog_cost = 10*19.50

daily_dog_cost = 195

total_cost = daily_dog_cost * number_of_days

total_cost = 195 * 3

total_cost = 585

Hence value of second_stay = 585

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote