Ex14 - Study Drill 3 - Add another Argument


Having difficulty adding another argument to Exercise 14.

Have tried various ways, but always get error.

Have a feeling I’m missing something simple…

1 from sys import argv
3 script, user_name, second = argv # I added ‘second’ as other argument
4 prompt = '> ’

lines 6 - 21 are same as code in book

Added following to add another argument to this script:

23 print(“What is your favorite app?”, second)

Get error message:

File “home/marks/…/ex14.py”, line 3 in
script, user_name, second = argv
Value error: not enough values to unpack (expected 3, got 1)

To run script in Terminal, I did:

$ python3 ex14.py Mark Excel

What am I doing wrong?

Thanks for your help.


Hi @ArchiMark - based on what you have uploaded, there is nothing incorrect. I wonder if the error is occurring elsewhere in the script, but you have clearly given three argument on the command line.

Can you upload all the code between two set of 3 backticks ( these `).

Right before this assignment print out argv:

script, user_name, second = argv

The rule is “always be printing”. If you have no idea what’s going with a variable, print it. If you don’t know why code is running, put a print statement. print print print.

Try that.

1 Like

THANK YOU gpkesley & zed for your help!

I relooked at the text I typed in VSC and finally noticed that I had a comma after ‘argv’ !!!

Deleted it and now script ran OK.

What is weird is that I can swear that I ran script OK before I modified it to add another argument. If that’s the case, then somehow I accidentally typed the comma while modifying script. But I can’t say for sure that’s when it happened.

So, now that I’ve got it working, I will try adding another argument as per study drill. Hopefully, this time I will be successful.

@ Zed

Thank you for reminding me about ‘printing’ to debug…

I should have known/remembered to do this since I’ve been watching your videos, where you say this all the time…and demonstrate it…will do that if I ever have another problem… :grinning:

Ohhhh that thing, yeah that’s stupid. But, why didn’t your code you pasted show that? Here’s what you pasted:

from sys import argv

script, user_name, second = argv # I added ‘second’ as other argument
prompt = '> ’

Where’s the comma?

You’re right, Zed, wasn’t there when I pasted code…so, somehow snuck in there afterwards…

1 Like
A free service run by Zed A. Shaw for learncodethehardway.org.