Advertisement

Prompting and Passing problem

Started by July 09, 2014 08:49 PM
4 comments, last by koka282 10 years, 5 months ago

i just learning execise13 from learnpythonthehardway.org :(

i should see:

$ python ex14.py zed

Hi zed, I'm the ex14.py script.
I'd like to ask you a few questions.
Do you like me zed?
> Yes
Where do you live zed?
> San Francisco
What kind of computer do you have?
> Tandy 1000

Alright, so you said 'Yes' about liking me.
You live in 'San Francisco'. Not sure where that is.
And you have a 'Tandy 1000' computer. Nice.

what should i do :( :

Untitled11.png

argv is a list. unpack it.

something like:


my_list = [1, 2, 3]
a, b, c = my_list

Edit: then a = my_list[0] b =my_list[1] and so on. Look up the lesson code once again :)

Advertisement

Without straight up giving you the answer and trying to nudge you along the right path:

argv is the list of arguments you give to python, in this case argv = ["m.py", "script", "user_name"]. If you were to print argv, this is what you'll see. You assign your 'script' and 'user_name' variables to argv, this means:

argv = ["m.py", "script", "user_name"]

script = ["m.py", "script", "user_name"]

user_name = ["m.py", "script", "user_name"]

So, when you are printing either 'script' or 'user_name', you are printing the string representation of that list.

can u post screen of what should i do ? :)

Ty all

Again, without straight up giving you the answer and trying to nudge you along the right path:

What is happening is you are assigning the entire list to 'script' and 'user_name' when what you want is only one element from that list (per variable). While I disagree with Lysy with the list unpacking suggestion in this situation (simply because not every element in the list is required), that is my own personal bias and it is a valid solution. I would suggest reading up on list unpacking (good to know at any rate) and lists in general.

More specifically, to retrieve an element from a list you must 'index' into it. Don't worry, it's very easy to do.

put screen if u can :)

This topic is closed to new replies.

Advertisement