Loops inside Loops

Attention: Our videos have subtitles in all partner languages. You can switch on subtitles in the youtube player by clicking the gear wheel and selecting your preferred language.

In this section we are revisiting loops and place a loop inside another loop. You will find out why this is useful and what you can do with this. We will loop inside of loops. You will learn to create while loops inside of while loops, further improving on the concept of loops. Your code will do very complex stuff with just a few lines

Working with a list of names
Create an empty list called names. Implement the following operations using list methods: a. Add three names (e.g., "Alice", "Bob", "Charlie") to the names list. b. Print the number of names in the list. c. Check if a name (e.g., "Bob") is in the list and print "Found" or "Not found" accordingly. d. Remove one name from the list. e. Print the final state of the list after performing all the operations. Your task is to write Python code to accomplish the above instructions using the names list.
Solution
 # Create an empty list of names
names = []

# Add three names to the list
names.append("Alice")
names.append("Bob")
names.append("Charlie")

# Print the number of names in the list
print("Number of names:", len(names))

# Check if a name is in the list
if "Bob" in names:
    print("Found")
else:
    print("Not found")

# Remove one name from the list
if "Charlie" in names:
    names.remove("Charlie")

# Print the final state of the list
print("Final list of names:", names)