Question

In: Computer Science

1. When creating your own functions, which of the following are good characteristics that make them...

1. When creating your own functions, which of the following are good characteristics that make them robust, sharable, and reusable (check all that apply)

the function's name is suggestive of its purpose and/or actions and includes a summary docstring

the function freely uses variables in the global namespace to perform its activities

the function only uses variables it is passed by calling code or it otherwise internally creates

the function only performs a limited number of actions

2. Following list is given.

L L = [20, ‘Hello’, ‘Hi’, 6, 9]

What is the type of L[-3] = ?

int

float

string

list

3. Functions are required to have the following number of parameters and return statements (check all that apply):

at least one parameter and one return statement

zero or more parameters and zero or more return statements

one parameter but zero or more return statements

one return statement but zero or more parameters

4. To repeat a code fixed number of times what should you use?

while loop

repeat loop

for loop

conditional structure

5. What is the value of 'total' at the end of the code?

total = 0
numbers = [11, 1, -1, -20, 15]
for number in numbers: 
total += number

Raise an error

10

6

16

Solutions

Expert Solution

Ans 1) Some good characterstics of user defined functions are:

  • Option (a) : the function's name should be suggestive of its purpose and/or actions which helps in better readability of code
  • Option (b) : The global variables should be avoided in good coding practices but it can be used if necessary.
  • Option (c): The functions should use the variables passed as arguments or should create its own variables as it helps in sharing and reusability of the code easily.
  • Option (d) : The function should perform limited number of actions as it helps to keep the code modular with different functions for different actions and hence better reusability of code. Because there may be case when only some part of function is needed for another code and hence modular functions help in these cases.

Ans 2) L = [20, ‘Hello’, ‘Hi’, 6, 9]

L[-3] will give the item from the list which is at 3rd position from last in the list due to '-'(negative) sign. So, the third item from last in the given list is 'Hi' which is a string.

Hence, option (c) string is correct.

Ans 3) Functions are required to have the following number of parameters and return statements.

Option (b) zero or more parameters and zero or more return statement is correct.

The arguments are not necessary in the functions and hence there can be 0 or more arguments in the function.

Also, the return statements depends on the type of the function (void, int, string, boolean etc). In void function, there should be 0 return statement, in other types, there should be 1 or more return statements.

Ans 4) To repeat a code fixed number of times what should you use?

We can use any loop type of code for repeating the statements in the code. For eg, do while, for loop, while loop, repeat loop etc.

So, option (a), (b), and (c) are correct.

Option (d) is wrong because the conditional structure consists of if-else statments and hence not used for repeatation of code.

Ans 5) What is the value of 'total' at the end of the code?

 total = 0
 numbers = [11, 1, -1, -20, 15]
 for number in numbers: 

    total += number

Option (c) 6 is correct.

It will add all the elements in the 'numbers' list given in the code. So the value of total will be 6.


Related Solutions

1. Explain, in your own words, characteristics that make a firm a good candidate for an...
1. Explain, in your own words, characteristics that make a firm a good candidate for an LBO. 2. Explain, in your own words, what is a contingent payment, why is it used and what are the common types of contingent payments. 3. Explain, in your own words, why there might be a conflict of interest in a management buyout. 4. Explain, in your own words, what an earnout agreement is and how it shares the risk of a merger deal...
1-Frogs are often considered a good indicator species. Explain what characteristics of frogs make them such...
1-Frogs are often considered a good indicator species. Explain what characteristics of frogs make them such good indicators of the health of their environment. 2-Ernie is strictly carnivorous, ignoring all health warnings. Ernie consumes 74 000 kJ of meat every day. Agricultural land can support this type of diet at 835.0 kJ/m2 of land used. Determine how much land it takes to support Ernie’s lifestyle.
Which of the following characteristics of chloroplasts make them seem more similar to bacterial cells than...
Which of the following characteristics of chloroplasts make them seem more similar to bacterial cells than to eukaryotic cells? ANSWERS: Translation is sensitive to chloramphenicol Alternate codons are found in the chloroplast genome Introns are present in genes DNA is not arranged in nucleosomes
Which of the following cost functions exhibits economies of scope when three (3) units of good...
Which of the following cost functions exhibits economies of scope when three (3) units of good one and two (2) units of good two are produced? 1) C = 50 − 5Q1Q2 + 0.5Q12 + Q22. 2) C = 15 + 5Q1Q2 + 2Q1 + 4Q2. 3)C = 5 + Q1Q2 + Q12Q22. 4)C = 10 + 4Q1Q2 + Q12 + Q22. Please tell me the # of the answer.and explain thanks.
What characteristics of protozoa make them resemble animals?
What characteristics of protozoa make them resemble animals?
C program with functions Make a dice game with the following characteristics: must be two players...
C program with functions Make a dice game with the following characteristics: must be two players with two dice. when player 1 rolls the marker is annotated when player 2 rolls the marker is annotated in other words, for each roll the added scores must be shown. Example: Round 1: player 1 score = 6 player 2 score = 8 Round 2: player 1 score = 14 player 2 score = 20 Whoever reaches 35 points first wins. if a...
Functions, Characteristics and Advantages of Transaction Processing System (TPS). Write around 250 words of your own...
Functions, Characteristics and Advantages of Transaction Processing System (TPS). Write around 250 words of your own and please don't take entirely from Google
Choose a company of laptops of your own choice and explain the following characteristics of the...
Choose a company of laptops of your own choice and explain the following characteristics of the chosen product. 1) Substitutes and complements goods of the product and their implication. 2) Major current and past reason for variation in demand and supply.
what properties of lipids make them a good source of storage?
what properties of lipids make them a good source of storage?
Identify your top three takeaways from the Economics and how you’ll leverage them to make good...
Identify your top three takeaways from the Economics and how you’ll leverage them to make good decisions. You can consider these questions as you reflect on your learning in this course: What did you learn that will help you make better decisions? What will you do differently at work or in your personal life as a result of being able to apply economic principles to your decision making? What advice would you give to someone who is just starting to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT