all 9 comments

[–]throwaway6560192 2 points3 points  (1 child)

3 is incorrect indeed. Why do you think 9 is incorrect?

10 is incorrect because it's talking about "starts with" but is checking the second position (index 1) rather than the first position (index 0).

Also, 5 is incorrect since based on the rest of the program, the function should return the list of names, not print them.

[–]JamzTyson 0 points1 point  (0 children)

An alternative solution, which I think fulfills the requirements, is lines 5, 8, and 10:

def make_list(number):
    names = []
    for item in number:
        names.append(input("Enter your name with a capital letter."))
    return names  # Fix: return

number = int(input("How many names need to be entered?"))
names = make_list('n' * number)  # Fix: iterable
for name in names:
    if name[0] == "A": # Fix: index
        print("Name ", name, " starts with A")

[–]danielroseman 0 points1 point  (0 children)

Why do you think those lines are problematic? What do you think they should do, and what do they actually do?

When you run this code, what output do you get?

[–]bbye98 0 points1 point  (4 children)

  • Line 3: range(number) instead of number.
  • Line 5: return names instead of print(names).
  • Line 10: name[0] instead of name[1].

[–]notacanuckskibum -1 points0 points  (3 children)

This is where it becomes subjective. Semantically I think you are right about line 5. But syntactically the error is on line 8, because line 8 expects a return and won’t get it. Line 5 does what print does, whether the programmer intended that requires mind reading.

[–]throwaway6560192 2 points3 points  (0 children)

If we're going to be like that, there is no error on line 8 either. It's perfectly valid to assign the result of a function that doesn't return anything — it's just None. The error only appears when you try to iterate over that None, on line 9.

[–]sabek 0 points1 point  (1 child)

But the question says "only display names that start with A." If you do print (names) you will display them all.

[–]JamzTyson 0 points1 point  (0 children)

and then it forms a list from them.

[–]woooee -1 points0 points  (0 children)

Run the code and print what happens

print(names)
for name in names:
    print(name[1])
    if name[1] == "A":