3.8k views
2 votes
Define stubs for the functions get_user_num) and compute_avg). Each stub should print "FIXME: Finish function_name" followed by a newline, and should return -1. Each stub must also contain the function's parameters Sample output with two calls to get_user_num) and one call to compute_avg): FIXME: Finish get_user_num() FIXME: Finish get_user_num() FIXME: Finish compute_avg() Avg: -1 1 ' Your solution goes here '' 2 4 user_num1 = 0 5 user_num2 = 0 6 avg_result = 0 7 8 user_num1 = get_user_num 9 user_num2 = get_user_num ) 10 avg_result = compute_avg(user_num1, user_num2) 11 12 print'Avg:', avg_result)|

User Myrna
by
5.3k points

1 Answer

3 votes

Answer:

Here are the stub functions get_user_num() and compute_avg()

def get_user_num():

print('FIXME: Finish get_user_num()')

return -1

def compute_avg(user_num1, user_num2):

print('FIXME: Finish compute_avg()')

return -1

Step-by-step explanation:

A stub is a small function or a piece of code which is sometimes used in program to test a function before its fully implemented. It can also be used for a longer program that is to be loaded later. It is also used for a long function or program that is remotely located. It is used to test or simulate the functionality of the program.

The first stub for the function get_user_num() displays FIXME: Finish get_user_num() and then it returns -1.

The seconds stub for the function compute_avg() displays the FIXME: Finish compute_avg() and then it returns -1.

Here with each print statement, there is function name after this FIXME: Finish line. The first function name is get_user_num and the second is compute_avg().

Next the function get_user_num() is called twice and function compute_avg() followed by a print statement: print('Avg:', avg_result) which prints the result. So the program as a whole is given below:

def get_user_num():

print('FIXME: Finish get_user_num()')

return -1

def compute_avg(user_num1, user_num2):

print('FIXME: Finish compute_avg()')

return -1

user_num1 = 0 # the variables are initialized to 0

user_num2 = 0

avg_result = 0

user_num1 = get_user_num() #calls get_user_num method

user_num2 = get_user_num()

avg_result = compute_avg(user_num1, user_num2)

print('Avg:', avg_result)

The method get_user_num() is called twice so the line FIXME: Finish get_user_num() is printed twice on the output screen. The method compute_avg() is called once in this statement avg_result = compute_avg(user_num1, user_num2) so the line FIXME: Finish compute_avg() is printed once on the output screen. Next the statement print('Avg:', avg_result) displays Avg: -1. You can see in the above program that avg_result = compute_avg(user_num1, user_num2) and compute_avg function returns -1 so Avg= -1. The program along with the produced outcome is attached.

Define stubs for the functions get_user_num) and compute_avg). Each stub should print-example-1
User Farhan Syah
by
5.1k points