01-02-2014, 03:50 PM
I'm new to Python, and I'm reading "learnpythonthehardway" and so far I think it's good, but i'm having some trouble with chapter 14 which talks about argvs.
My script:
But then it asks me "Add another argument to your script"
So I assume it's asking me to add another argument in the second line being
But I don't know what to put, since i'm having trouble thinking about where I would put it.
So could anyone please just add a new arg for me to inspect to understand what I could have done?
I added a new arg called nick_name, like so:
My full script now:
My script:
PHP Code:
from sys import argv
script, user_name = argv
prompt = '> '
print "Hi %r, i'm the %r script, nice to meet you." % (user_name, script)
print "If you don't mind, %r, i'd like to ask you a few questions?" % user_name
print "Do you like me, %r?" % user_name
opinion = raw_input(prompt)
print "Where do you happen to reside, %r?" % user_name
residence = raw_input(prompt)
print "So what operating system do you operate on, %r?" % user_name
OS = raw_input(prompt)
print "And lastly, what race are you?"
race = raw_input(prompt)
print """
So, you said %s when I asked if you liked me.
You live in %s, nice area I guess.
You operate on %s, pretty lame if you ask me.
You are %s, very interesting.
""" % (opinion, residence, OS, race)
But then it asks me "Add another argument to your script"
So I assume it's asking me to add another argument in the second line being
PHP Code:
script, user_name = argv
But I don't know what to put, since i'm having trouble thinking about where I would put it.
So could anyone please just add a new arg for me to inspect to understand what I could have done?
I added a new arg called nick_name, like so:
PHP Code:
script, user_name, nick_name = argv
My full script now:
PHP Code:
from sys import argv
script, user_name, nick_name = argv
prompt = '> '
print "Hi %r, i'm the %r script, nice to meet you." % (user_name, script)
print "If you don't mind, %r, i'd like to ask you a few questions?" % user_name
print "%r, make up a nickname please.?" % user_name
nick_name = raw_input(prompt)
print "%r, your nickname is %r? Wow." % (user_name, nick_name)
print "Do you like me, %r?" % user_name
opinion = raw_input(prompt)
PHP Code:
Traceback (most recent call last):
File "ext13.py", line 3, in <module>
script, user_name, nick_name = argv
ValueError: need more than 2 values to unpack