For your hobbies: Not printing properly


#1



https://www.codecademy.com/en/courses/python-beginner-en-cxMGf/1/2?curriculum_id=4f89dab3d788890003000096#


Name one of your hobbies: I
[built-in function raw_input]
Name one of your hobbies: L
[built-in function raw_input, built-in function raw_input]
Name one of your hobbies: O
[built-in function raw_input, built-in function raw_input, <built-in function raw_input]
None


I expect a list containing [I, L, O], but the code does not seem to accept the input.
The course states that I am correct and is letting me continue to the next exercise, but I still think this is incorrect.

hobbies = []
# Add your code below!
for i in range(3):
    raw_input("Name one of your hobbies: ")
    hobby = raw_input
    hobbies.append(hobby)
    print hobbies


#2

raw_input prompts the user, the result of which you store in a variable, why do you need raw_input twice then?


#3

I removed the second raw_input, still getting the same thing

hobbies = []

for i in range(3):
raw_input("Name one of your hobbies: ")
hobbies.append(hobby)
print hobbies

Name one of your hobbies: A
[built-in function raw_input]
Name one of your hobbies: B
[built-in function raw_input, built-in function raw_input]
Name one of your hobbies: C
[built-in function raw_input, built-in function raw_input, built-in function raw_input]
None

Just noticed that < and > together actually stops the code from showing. Editing previous post.


#4

you should store the result of prompting the user in a variable, and append this variable to list


#5

I'm a bit lost. I feel like I'm missing something extremely obvious. I thought:

hobby = raw_input

was storing a variable, but now I'm confused.


#6

here you prompt the user:

raw_input("Name one of your hobbies: ")

i don't see you store the result of this prompt in a variable?

this is trivial, how do we make variables?


#7

Somehow replied to previous comment.


#8

and you should have merged those two lines correctly, which you didn't


#9

I'm sorry, but I'm completely lost here.


#10

declaring variable and giving it value:

x = "value here"

this value can also be the result of calling raw_input to get user input


#11

Hi @ptraynor894,

What @stetim94 is referring to here is your method of storing your prompted data.

You do this:

raw_input("Say something: ")
x = raw_input

However, that is not proper syntax. You can't just prompt the user for something and then make a variable equal to raw_input (raw_input is a built-in function, not a variable). In order to store a prompt within a variable you need to do something like this:

x = raw_input("Say something: ")

Notice the difference?


#12

It's fine now, got past it.

EDIT: Code used:

for i in range(3):
hobby = str(raw_input("Name one of your hobbies: "))
hobbies.append(hobby)
print hobbies


#13

Hi @ptraynor894,

To call a function, you must follow the name of the function by parentheses, and include any necessary arguments within the parentheses.

The name of a function, when used in an expression without its being followed by parentheses, refers to the function, itself, rather than referring to the result of calling the function. raw_input is a Python built-in function.

Here, you assigned the raw_input function to hobby, rather than assigning the result of calling the function to hobby ...

    hobby = raw_input

That is why your initial attempt at the exercise was rejected.

Thanks, @stetim94 and @aquaphoenix17, for explaining what needed to be done to complete the exercise.


#14

Please help.Why do I get u'fishing etc in my hobbies?

hobbies = []

Add your code below!

for i in range(3):
hobby = raw_input("type in a hobby: ")
hobbies.append(hobby)
print hobbies

type in a hobby: fishing
type in a hobby: gardening
type in a hobby: singing
[u'fishing', u'gardening', u'singing']
None

Thanking you in advance


#15

codecademy stores the result of raw_input as unicode, convert it to string using str()


#16

great thank you.I am grateful. The "u" has disappeared with hobby = str(raw_input("......")) as you suggested but I can live with the quotation marks( as in 'fishing') for now. Cheers


#17

if you print a list, of course the "" or '' which indicate string will show.

you can loop over the list and print out each item, then it just show the hobby


#18

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