Lab 8: More Lists

Today's quiz is this google form, with 3 multiple choice questions. This needs to be done in the first few minutes of lab and is not available until midnight like other quizzes, because it is so short.

The lab description and test cases can be found in Zybooks 3.26 The description shown below is included for archival purposes.

Complete the program that:

  1. Prompts for names, adding each one to a list, until "done" is entered as a name.

  2. Display the list.

  3. Then prompt for a name to be removed

  4. Again display the list.

  5. Display a random name.

For instance, running the program could look like:

Enter names, followed by "done":

Kira

Annie

Le'She

Safiyah

done

The list of names is: ["Kira","Annie","Le'She","Safiyah"]

Name to remove: Safiyah

The list of names is: ["Kira","Annie","Le'She"]

Random name is: Annie


Running the program a different time might look like:

Enter names, followed by "done":

Ali

Getze

Lorena

done

The list of names is: ["Ali","Getze","Lorena"]

Name to remove: Getze

The list of names is: ["Ali","Lorena"]

Random name is: Ali


Hints:

  • Each time a name that is not 'done' is entered, append it to the list using names.append(…)

  • If the name to remove does not match any name on the list, then nothing will be removed.

  • To get the random name, find the length of the list using len(…), use random.randrange(0,…) to get a random index value for one of the list elements, and display that list element.