Jump to content
  • Advertisement
Sign in to follow this  
koka282

Prompting and Passing problem

This topic is 1383 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

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 :)

Edited by Lysy

Share this post


Link to post
Share on other sites

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.

Edited by AnEverydayGuy

Share this post


Link to post
Share on other sites

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.

Edited by AnEverydayGuy

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!