10.) For your hobbies


#1

Why do both pieces of code work? What is the difference? Thank you!

1.)

hobbies = []

Add your code below!

for i in range(3):
i = raw_input("Tell me one of your favorite hobbies: ")
hobbies.append(i)

print hobbies

2.)

hobbies = []

Add your code below!

for num in range(3):
hobby = raw_input("Tell me one of your favorite hobbies: ")
hobbies.append(hobby)

print hobbies


#2

i and hobbies, for starters. Is this a trick question?


#3

In the second one num is not used again. From previous lessons I thought you had to reuse the variable.


#4

Ah, I see now. In most cases the variable is arbitrary unless we are specifically instructed to use it by a given name. Common iterator names are either i, j, k, or singulars of a given plural named object.

for fruit in fruits:

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.