Question: PYTHON MULTI CHOICE URGENT 1) Consider the following code segment. It is supposed to count the number of digits (0 - 9) in a string,

PYTHON MULTI CHOICE URGENT

1)

Consider the following code segment. It is supposed to count the number of digits (0 - 9) in a string, text.

count = 0 for char in text: ____________________ count = count + 1 

What line of code should be placed in the blank to achieve this goal?

if text[char] >= "0" and text[char] <= "9":
if text[count] >= "0" and text[count] <= "9":
if char >= "0" and char <= "9":
if text >= "0" and char <= "9":

2)

Consider the following code fragment (assumed to be in an otherwise correct program):

class MyClass: shared_max = 200 def get_max(self): return self.shared_max def set_max(self, new_max): self.shared_max = new_max 

Assume there are no omitted statements within this fragment -- you see everything. Check the true statements (may be more than one):

Both methods refer to an instance attribute, self.shared_max.

Both methods refer to the static attribute, MyClass.shared_max.

The mutator refers to an instance attribute, self.shared_max, while the accessor refers to the static attribute, MyClass.shared_max.

3)Which for loop prints data across each row in the following code snippet?

for i in range(1, 4): for j in range(1, 4): print("x", end="") print("")

The inner for loop
The outer for loop
Both for loops
Another missing for loop

4) What value is printed by the code snippet

name="John R. Johnson" first_name="John" location=name.find(first_name) print(location)

5) Given the following code snippet:

MIN_SPEED=45 MAX_SPEED=60 speed=55 if not(speed MIN_SPEED): speed=speed+10 print(speed)

what output is produced?

45

55

65

50

6) What does the following code segment do?

x=0 for i in range(1, len(values)): if values[i] < values[x]: x=i

It finds the largest item in values and stores it in x

It finds the position of the largest item in values and stores it in x.

It finds the smallest item in values and stores it in x

It finds the position of the smallest item in values and stores it in x

7) You are creating a program that includes a dictionary where the keys are people's namesand the values are their favorite foods.

Which of the following statements adds an entry to the dictionary that indicates that Ravi's favorite food is chocolate?

favorite_foods["chocolate"] = "Ravi" 
favorite_foods.add("Ravi", "chocolate") 
favorite_foods = {"Ravi", "chocolate"} 
favorite_foods["Ravi"] = "chocolate"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!