Question 2. Complete the following conditional statement so that the string 'More please' is assigned to the variable say_please if the number of nachos with cheese in ten_nachos is less than 5. Hint: You should not have to directly reference the variable ten_nachos.

Respuesta :

Answer:

The solution code is written in Python 3:

  1. ten_nachos = [True, True, False, False, False, True, False, True, False, False]
  2. count = 0
  3. for x in ten_nachos:
  4.    if (x == True):
  5.        count += 1
  6. if count < 5:
  7.    say_please = "More please"

Explanation:

By presuming the ten_nachos hold an array of True and False values with True referring to nachos with cheese and False referring to without cheese (Line 1).

We create a counter variable, count to track the occurrence of True value in the ten_nachos (Line 3).

Create a for-loop and traverse through the True and False value in the ten_nachos and then check if the current value is True, increment count by 1 (Line 5 - 7).

If the count is less than 5, assign string "More please" to variable say_please (Line 9 -10).