Help in Python test application

Hey there,
I thought I am fairly used to python but this test has me scratching my head.
I am supposed to find mistakes in the 11 lines of code shown bellow but I can’t seem to figgure out what is wrong. Help would be appreciated.

The task is the following:

Which lines of code contain errors?
The program asks the user first for the number of names, then for the names, and then it forms a list from them.
From those names, only those that start with a capital letter “A” are displayed on the screen.

When troubleshooting, we need to ask ourselves two questions:

  1. What do we expect the program to do?
  2. What is the program actually doing?

And then we need to find what causes the discrepancy between the two.

In this case, the expected result of entering Alice, Bob, Carl is that only “Alice” gets printed. Let’s see what actually happens:

How many names need to be entered?3
Traceback (most recent call last):

  File "", line 9, in <module>
    names = make_list(number)

  File "", line 3, in make_list
    for item in number:

TypeError: 'int' object is not iterable

So, the first problem is on line 3, where the script attempts to loop over the value number. But number is an int, which is not iterable and therefore cannot be looped over.

So to solve this first problem, you need to find the answer to the following question: How can you create an iterable from an int?

1 Like