Question

Question 1 (1 point) Which of the following is a reason to use functions? Question 1...

Question 1 (1 point) Which of the following is a reason to use functions?

Question 1 options:

To make it easier to read by keeping sections of code shorter.

To avoid duplicating code.

all of the above

To make the code more organized.

Question 2 (1 point) When the execution of a function ends, what Python code is executed next?

Question 2 options:

The function is automatically executed again.

The line of code immediately after the end of the function.

The program ends without executing any more code.

The code immediately after where the function was called from.

Question 3 (1 point) How do you determine which is the last line of a function?

Question 3 options:

The next non-blank line contains a def statement.

The next non-blank line of code is indented at the same indentation level as the def statement for the function.

The last return statement is the last line of the function.

The first return statement is the last line of a function.

Question 4 (1 point) How do you determine if a name is a variable holding a value or if it is a function call?

Question 4 options:

If it is a function call, it will start with an uppercase letter.

If it is a function call, it will have parentheses after the name to call the function.

If it is a variable, it will be on the right-hand side of an assignment statement.

If it is a variable it will be part of an expression.

Question 5 (1 point) What variable names does a function have access to?

Question 5 options:

Parameters that are passed to the function and any variables created in the function.

Only the parameters passed to the function.

Only variables created in the function.

All variables used in a program.

Question 6 (1 point) How do you determine which actual parameter to assign to each formal parameter?

Question 6 options:

The names of the formal parameters must match.

The order of the parameters indicates how they are assigned.

You can only pass one parameter to a function.

You manually assign each parameter at the beginning of the function.

Question 7 (1 point) What is the purpose of the return statement in a function definition?

Question 7 options:

To cause execution of the function to end and return to the code that called it.

To send a value or values back to the code that called it.

either a or b

none of the above

Question 8 (1 point) When a function returns a value, the options for the caller are to

Question 8 options:

all of the above

use the result as part of an expression (e.g., x = y + math.sqrt(5))

ignore the return value

assign it to a variable (e.g., x = math.sqrt(5))

Question 9 (1 point) When a function returns a value, usually you want to

Question 9 options:

store the result in a variable

use the result as part of an expression

ignore the returned value

either b or c

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Question -1

Answer :

All of the above

Explanation

While using the functions in any programming language then the program will be more organized and the length of the program will decrease, which improves the readability of the program.

Question – 2

Answer:

The code immediately after where the function was called from.

Explanation

          It is the properties of any language is that the execution of the statements will be one after another. So after completion of a function then it will execute the immediate statement after its call.

Question – 3

Answer:

The next non-blank line of code is indented at the same indentation level as the def statement for the function.

Explanation

          In python the indentations plays an vital role for formation of blocks. So after the completion of a function the next statement will be on same indentation level as def statement.

Example:

In the above code the function terminates just before the statement

a=int(input(“Enter a number”))

Question – 4

Answer:

If it is a function call, it will have parentheses after the name to call the function.

Explanation:

In any programming language the function name always terminated by a pair of parenthesis.

Question – 5

Answer:

Parameters that are passed to the function and any variables created in the function.

Explanation:

The function can use the variables that are passed to it as argument and if any other variable declared inside it then those can also be used inside the function. Other variables can not be used by function because of those will be out of scope rules.

Question – 6

Answer :

The order of the parameters indicates how they are assigned.

Explanation

During the function call one have to maintain the order of parameters according to these the parameters will assign in the definition part of function as formal parameters.

Question - 7

Answer:

To send a value or values back to the code that called it.

Explanation:

The return statement will return the final result of function to its calling part that means the statement which called to the function.

Question -8

Answer

assign it to a variable (e.g., x = math.sqrt(5))

Explanation

Since the function will return a value so assign it to a variable.

Question -9

Answer:

store the result in a variable

Explanation

Since the function will return a value so assign it to a variable

Add a comment
Know the answer?
Add Answer to:
Question 1 (1 point) Which of the following is a reason to use functions? Question 1...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 1 The following function header represents which programming language? double calc_weekly_pay( double hours_worked, double pay_rate)...

    Question 1 The following function header represents which programming language? double calc_weekly_pay( double hours_worked, double pay_rate) Question 1 options: Python A C-based language FORTRAN COBOL Question 2 One of my favorite quotes from Jeanette Wind is "Computational thinking is using abstraction and decomposition when attacking a large complex task or designing a large complex system." This supports using _____________ when developing programs. Question 2 options: Repetition structures Assignment statements Selection structures Functions Question 3 The following assignment statement exhibits which...

  • The purpose of this lab is to practice working with Python's higher order functions and ternary...

    The purpose of this lab is to practice working with Python's higher order functions and ternary operator. Write all of your code in one file named lab2.py. You can write the code for items 1 through 6 directly inside the main function. Let a be the list of values produced by list(range(1, 11)). [1 point] Using the map function and a lambda argument, write an expression that produces a list of the cubes of the values in a. Assign the...

  • Question 14 (1 point) Suppose the following function foo was called with a list of size...

    Question 14 (1 point) Suppose the following function foo was called with a list of size 5. How many operations on the handler stack (push or pop) would result during the execution of the function? def foo (L): r = 0 for x in L: try: # convert x to int int (x]) r = r + S except ValueError: return 0 S return r 2 5 112 10 6

  • QUESTION 1 Which statement results in the value false? The value of count is 0; limit...

    QUESTION 1 Which statement results in the value false? The value of count is 0; limit is 10. (count != 0)&&(limit < 20) (count == 0)&&(limit < 20) (count != 0)||(limit < 20) (count == 0)&&(limit < 20) 10 points    QUESTION 2 If this code fragment were executed in an otherwise correct and complete program, what would the output be? int a = 3, b = 2, c = 5 if (a > b) a = 4; if (...

  • Question 14 (1 point) Suppose the following function foo was called with a list of size...

    Question 14 (1 point) Suppose the following function foo was called with a list of size 5. How many operations on the handler stack (push or pop) would result during the execution of the function? def foo (L) : r = 0 for x in L: try: # convert x to int = int (x]) r = r + S except ValueError: return 0 S return r 0 return r 0 2 5 O 12 10 6

  • Number 1) Which of the following statements imports a module into the default namespace? a. from...

    Number 1) Which of the following statements imports a module into the default namespace? a. from temperature import * b. import temperature as t c. import temperature as temp d. import temperature Number 2) Which of the following statements imports a module into the global namespace? a.from temperature import *   b. import temperature as temp c. import temperature as global d. import temperature Number 3) Code Example 4-2 def get_volume(width, height, length=2):     volume = width * height * length...

  • T F a) Void Functions can use reference parameters. T F b) Arguments corresponding to reference p...

    T F a) Void Functions can use reference parameters. T F b) Arguments corresponding to reference parameters can be variables only T F c) The C++ statement retum "hello can be used with an integer value-retuming function T F d) Static variables maintain their value from function call to function call. T F e) The components of a C++ array must be homogeneous T F fA hierarchical structure has at least one component that is itself a structure. T F...

  • 1. Write a statement that calls a function named showSquare, passing the value 10 as an...

    1. Write a statement that calls a function named showSquare, passing the value 10 as an argument. 2. Write the function prototype for a function called showSquare. The function should have a single parameter variable of the int data type and areturn type of void. 3. Write the function prototype for a function called showScoreswith a parameter list containing four integer variables and a return type of void. 4. Look at the following function definition: double getGrossPay(int hoursWorked, double payRate)...

  • These are questions in python please! 1) What is the value of variable answer as the...

    These are questions in python please! 1) What is the value of variable answer as the result of the function call in the preceding question. Here is the code again: def my_function(a, b): c = (a + b) * (b - a) return c The call was made with a value of 3 for a and 7 for b. 2)  Write a function named formula that takes three parameters and returns, as its value, the first number plus 5 times the...

  • You should implement several functions that the Phone Contacts program will need Each function with take...

    You should implement several functions that the Phone Contacts program will need Each function with take in data through the parameters (i.e., variables names listed in parentheses) and make updates to data structure that holds the contact information, return, or print information for a particular contact. The parameters needed are listed in the table below and each function is described below that 1. Make an empty dictionary and call it 'contacts'. Where in your code would you implement this? Think...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT