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

PYTHON MULTI CHOICE 1) What is wrong with the following code snippet? mystery(10

ID: 3738413 • Letter: P

Question

PYTHON MULTI CHOICE

1) What is wrong with the following code snippet?

mystery(10, 2)
def mystery(num1, num2):
result = num1 ** num2
return result

nothing, it will return 20

nothing, it will return 100

2) Consider this function definition:

This function has the following problem -- or none (only one correct choice):

It will always produce an infinite recursive call to itself resulting in a run-time error.

It will always return the same number no matter what is passed in as an argument from the main function.

Nothing is wrong;

It will sometimes return a -1 without error, and other times produce an infinite recursive call to itself resulting in a run-time error.

3) Which are true about instance variables (attributes) of a class

(check all that apply):

They should usually be defined and assigned in the __init__() method (constructor) of that class.

They should be private so that only the object’s methods can directly access them. This protects the object’s data attributes from accidental corruption.

Member instance methods of the same class must use self. (or, whatever the first formal parameter is, followed by the dot) before their names in order to access them.

The statements

will cause how many Card objects to be instantiated? (only one correct choice):

4) A mutator's job is to (check all that apply):

protect instance or class data

return the value of the mutator's associated member data to the client.

set value(s) of data as requested by the client, if the value(s) the client supplies (supply) is (are) deemed acceptable by the class designer.

print errors if bad data is passed.

5) Which statements are true about the built-in Python tuple data type?

(check all the are true)

- tuples are mutable.

- Elements of a tuple can themselves be mutable types.

- If some_var is a tuple that has exactly 10 items in it, the following two variable names reference the same object:

   and

nothing, it will return 20

Explanation / Answer

Question 1

Answer:

nothing, it will return 100

Question 2

Answer:

It will always produce an infinite recursive call to itself resulting in a run-time error.

Question 3

Answer:

They should be private so that only the object’s methods can directly access them. This protects the object’s data attributes from accidental corruption.

They should usually be defined and assigned in the __init__() method (constructor) of that class.

Member instance methods of the same class must use self. (or, whatever the first formal parameter is, followed by the dot) before their names in order to access them.

Question

The statements

card1 = "hi mom"

card2 = 3

card3 = Card()

my_card = card3

card1 = Card()

Answer:

3

Question 4

Answer:

protect instance or class data

set value(s) of data as requested by the client, if the value(s) the client supplies (supply) is (are) deemed acceptable by the class designer.

Question 5

Answer:

Elements of a tuple can themselves be mutable types.

If some_var is a tuple that has exactly 10 items in it, the following two variable names reference the same object:

some_var[8]

and

some_var[-2]