Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions source/week-2/loops/for.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
for name in ['John Doe', 'Jane Doe']:
print(name)

people= ['John Doe', 'Jane Doe', 'Josephine Magu']
for name in range(len(people)):
print('Current person:', people[index]))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index is undefined, I believe you meant name

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are looping in respect to the range which is the length of the list, instead, you can iterate over the list like this.

people= ['John Doe', 'Jane Doe', 'Josephine Magu']
for person in people:
	print('Current person: ', person))