Ex13.py nothing works right

I was doing so good until I got to Ex13 in lpthw. (1st book.) I did the program on page 42 and I got the same warning that is at the bottom of page 43, but where that says, (expected 4, got 3) mine says ‘got 1’. So after spending too much time on that, I went to the programs on pg. 43. They tell me that the $ symbol is not valid. In the past, when I got a ^ pointing out a problem, I would look for something wrong before it, but there is nothing there to go wrong. I’m using 3.7 although the book is in 3.6. Did they change that in 3.7? Thank you.

IHi @Not2smart.

About the parameters:

If you put in 3 parameters in a function

def plus(a, b, c)

Then Python have three variables (correct me if that was wrong name) to work with.

print(a + b + c) # If you want to see the result.
return a + b + c # you want to pass it on to another function

Then you have to load the variables with something.

plus(1, 2, 3) 
# three arguments for three parameters

If you got a Traceback the “^” use to point out the reason for the problem.
I use to find my errors above that line usually.
A missing " ) " or " : " or some other small character.

Put up your code here for us to see.
Wrap it in with:

Your code in here…
[/code ]

minus the blank space between “code” and " ] "

There are many eyes here.
Eager for a problem to solve.

Perhaps this problem not was about parameters and argument?
It was ’ (expected 4, got 3) ’ that make me think so. I use to get these error messages when missing a argument.

I’m not sure how to paste the code up here. I use Notepad++ to write the code, but I don’t think I can copy it from there. When I open it in Win Powershell, I don’t know how to copy from there. So the only way I can post it on here is to type it in, and that may not be the code I’m working with. I’m sure I typed it correct from the book, but I will examine it again and see if I messed up. Thank you.

It’s easyer than you think @Not2smart: Just mark the desired text in your editor (Notepad++) and paste it between code brackets here in the forum like this:
Your Code
In Powershell you can also mark the desired text but you have to copy it with the right click of your mouse.

Hope that helps.

Oh, actually @Not2smart, what @DidierCH has is right but you might need some more baby steps to do the code paste:

  1. In notepad++ select the text you want to share here with your mouse or “select all” (usually ctrl-a).
  2. Use ctrl-c (hold down ctrl and hit c) to copy it.
  3. Come to the forum where you’re typing your message and type:


  1. Now, hit enter and put your cursor right under this, then hold down ctrl and hit v (ctrl-v).
  2. Your code is pasted into the text, but you have to end it, so now hit enter and type:


Then you can submit it. If you’re doing this on a first post it’s good to write up what’s happening, how it’s going wrong, and what you’ve tried already.

1 Like

I give up! I have worked a week on this ex13 or should I say pg. 42 & 43, and have come to the conclusion that this is a poorly written chapter. First it starts off with a ‘simple’ 7 line program that doesn’t work. Then you are purposely confused with the words features vs. modules. Then in ‘What you should see’ it says, “If you type only python 3.6 ex13.py, you are doing it wrong!”. Hey, I’m new at this and the last 12 examples have used that and only that. Why would I use anything else? Then I have three other programs to copy that also don’t work. They stop at the $ sign at the very beginning. I’m beginning to fear this book is like two other books and one very expensive video course I bought, that got to a certain point and assumed I have a masters degree in computer science. Maybe the best thing to do is just move on to the next chapter and perhaps later this will make sense. I wish those that write computer programming books would beta test their work with 100 students and see if they can make heads or tails of what is being written. To just put out a bunch of gobble de gook and hope some one can get it is not how it is should be done.

Hello @Not2smart

Don’t worry. These feelings are normal in the beginning.
I have had them hundreds of times.
Take a break for a day or two. Come back and give us the code you have written.
There is always someone here that can give you help so you can get going again.

Remember to do the study drills. They are very important in the beginning. Trust me.
I skipped them when I first started to learn python from this book. It came to a stop when I just didn’t understood anything (again).
So I started over from the beginning. Did twice as much study drills the first 40 exercises.
Now I am almost finished with the book. But it took me two years.

Don’t give up!
Get up and going again.

1 Like

Continuing the discussion from Ex13.py nothing works right:

Ok. I have not done the study drills and was wondering if there was something I was missing in them that may be causing my problems. As for posting the code, it is the same code as in the book. I have deleted it so many times, and checked it carefully so I’m sure I have it right, at least one of those times. Thank you for the encouragement.

Hello again.

Tell us what kind of computer you have. PC, Mac or Linux?
Which editor do you use to write code?
Perhaps it gives a clue where the problem are.
(forget about that. I saw in previous posts what you have)

I tried this exercise out now. I remember the first time I did this exercise I had some problem to understand I had to call the code with:

python ex13 I say hello
  • ”python3 ex13.py” to run the file ex13.py
  • “I” is the value for variable: first
  • “say” is the value for variable: second
  • “hello” is the value for variable: third

First I want to tell the webmaster that I typed in my password correctly several times and it kept telling me it was wrong, so I just set up a new password. Anyway, I found one problem with my code, that was in the book Zed says to type an $ character, in the first line. However, I looked back in the book and realized that Windoze does not use that character. So now, I have the code that I’m entering and below the line is the way it comes up in the Powershell.
python ex13.py first 2nd 3rd
The script is called: ex13.py
Your first variable is: first
Your second variable is: 2nd
Your third variable is: 3rd

PS C:\Users\Ric> cd lpthw
PS C:\Users\Ric\lpthw> python ex13.py
File “ex13.py”, line 1
python ex13.py first 2nd 3rd
SyntaxError: invalid syntax
PS C:\Users\Ric\lpthw>


Thank you. Not2smart.


Does your code looks like this:

from sys import argv

script, first, second, third = argv

print("the script is called", script) # this is actually the fist variable 
print("Your first variable is:", first) # second
print("Your second variable is:", second) # third
print("Your third variable is:", third) # fourth


I have this code in a file called ex13.py
When I want to run this code I have to type in a terminal
(powershell in your case):

python ex13.py I say hello

This gives me the output:

('the script is called', 'ex13.py')
('Your first variable is:', 'I')
('Your second variable is:', 'say')
('Your third variable is:', 'hello')

If your code is not working, then try this code.
Change something (one thing at the time), see whats happening.
If it stop working fix it back and get it working again.
Take away parts of the code.
Add something to it.
Remember: the number of parameters (python ex13.py parameter1, parameter2) has to be equal to arguments (argument1, argument2).

Show us your code when you got it working.
Or if you need more help.

You ask does my code look like yours. No it looks like the one I copied and pasted. Your sample is from page 42. I was sending the code from page 43. Is the code on page 43 supposed to be added to the code on page 42? As to adding or taking away parts of the code, I don’t know much of anything about code so I have no idea what to add or subtract. Thank you. Not2smart.

My mistake. I just looked at the title of this thread.
According to my book (PDF) it seemes that you are at exercise 3
I dont think we have the same book format.
So I dont know whats on page 42 or 43 in your book.

I tried to help you with exercise 13.

I hope its useful when you get there.

Hello @Not2smart the code which is you are referring to is the output of the code shown by @ulfen69 which is on page 42. when you run the code given on page 42 what you get output which given in the book on page 43.
there is nothing to add or subtract in code
you can see that zed shown another way to run the code with names of fruits which is wright after the code which you have shown
try to figure out what you are giving at command line with name of your script and try to understand that where it is going in the script

i’ll suggest you to look carefully on line 2 of above code

Ok, I think my problem might be that argv thing. I have the book Python In A Nutshell, and I’ll try to find out what that says about it. If I can’t get it figured out, at this point I will just move on. Thank you all for your help, and I still say this chapter is poorly written. I have tried to learn VB6,Just Basic and Liberty Basic. It seems that in all of them, you get to a certain point and the author seems to think you have a degree in computer science. At least with Python, there seems to be a good supply of info and people to help you out. Not2smart.

Hello @Not2smart.

I would not say its poorly written.
Perhaps it just not work for you.
Look up other tutorials about argv on internet.
Try their examples to see if works better.
Then come back and try again.
You paid for this book right? Dont throw it away.

I thought the same about Python. The basic was easy. When I wanted to learn more I had to try harder.
I still feel frustration every now and then.
But I get up when I have given up. So far every time. :blush:

I am soon finished the book after two year.
You can do it too.

1 Like

Hey, so you can copy code here easily:

  1. Hold down the ctrl key and press a then c. That’s selects all the code in your Notepad++ and copies it.
  2. Come here and put the cursor into the reply field.
  3. Type [code]
  4. Hit enter.
  5. hold down ctrl and hit v. That will paste the code here.
  6. Then type: [/code]

Try that then show me the code because I’m curious what’s going on here.