10. For your hobbies


#1



hobbies = []

# Add your code below!
for x in range(3):
    hobby = raw_input("Whats your hobby?")
    hobbies[x] = hobbies.append(hobby)

Hi, is this the best way to execute this task? I get the proper outcome, and i feel like im finally confident enough to handle these tasks on my own, i just want to know if this is the best or satisfactory way to complete this task.

thanks in advance,


#2

It looks so. That seems like the most efficient way to do that, although you might want to make that a function, so you could call it later.


#3

im specifically concerned about the hobbies[x] = hobbies.append(hobby)

is that statement really any different from simply putting hobbies.append(hobby) ? since the list starts at 0 and my counter in my loop does as well, that part seems a little...redundant. since appending to an empty list will start at zero as well.

More over, does setting it up in that way have any negative effects? i put the code in my 1st post thru www.pythontutor.com and it never appended the user input stored in the hobby variable into the list, although it also didnt throw any errors either.


#4

Hmm, the hobbies[x] part is a bit redundant. A slightly easier way to get the same result would be to have:

hobbies = []

for hobby in range(3):
hobby == raw_input("Whats your hobby?")
hobbies.append(hobby)


#5

Is there any way that the script ask : "please enter your first hobby:" , "please enter your second hobby :" , and so on, smartly ?


#6

hobbies = []

for hobby in range(3):
    hobby = raw_input("Input a hobby: ")
    hobbies.append(hobby)

hobbies[x] seems like your only downfall in this code.


#7

Hi @farbodemami,

I happened to chance upon this thread, and gave it some thought. A way to do it might be:

Except that this doesn't use range() :stuck_out_tongue:


#8

Hey guys! The following is my code. I changed it a bit to have it printed as a list after print.

hobbies = []

for hobby in range(3):
    hobby1 = input("first hobby:    ")
    hobby2 = input("second hobby:    ")
    hobby3 = input("third hobby:    ")
    hobbies.append(hobby1)
    hobbies.append(hobby2)
    hobbies.append(hobby3)
    print(hobbies)
    break

first hobby: playing pool
second hobby: programming
third hobby: running
['playing pool', 'programming ', 'running ']

`

Good luck, everyone!


#9

if you made print hobbies you will have wrong out put


#10

you do know that this lesson did not require a print?

It's not to gain a proper response but to gain the outcome that they asked in the lesson. But then again i could be wrong but the code I posted here worked for me, good luck.