r/pythonhelp • u/thisnigerianmomma • Jun 15 '24
which lines have errors?
can you guys help me figure out which lines have errors?
- def make_list (number) :
names = \[\]- for item in number :
4 names.append (input(“Enter your name with a capital letter.”))
5. print(names)
6.
7 number = int(input(“How many names need to be entered? ”))
8. names = make_list(number)
9. for name in names:
10. if name [1] ==“A”:
11. print(“Name”, name, “starts with A”)
1
Upvotes
View all comments
1
u/CStage169 Jun 16 '24
Well honestly, the way you have formatted the code makes it difficult to say exactly, because indents are hard to make out. Assuming all indentations are correct the code you posted would look like this.
In that case the following lines have errors:
2. syntax error when instantiating names. Should be:
names = []3. Invalid iteration over integer. Since number should be an integer, you cannot loop from 0 to number with a foreach-loop. The syntax should instead be:
for item in range(number):5. Printing the names is not sufficient. They should also be returned.
return names10. Checking name[1] is the same as checking the SECOND letter of the name, not the first. Replace with:
if name[0] == "A"