EX 19 and 21 Power Shell Issues

Hello all!

I’ve been goin through the book and have been having a great time so far. However, I started to run into issues with Ex 19. I decided to skip ahead, had no issues with Ex 20, but Ex 21 had the same issue and convinced me I needed help. Pictures are from Ex 21.

It’s not letting me imbed two images so I’ll try to do a follow in the comment for the result. If that doesn’t work, it simply bounces me back to C:\Users\krisk\Desktop\python

I’ve run into errors in the past but have been able to solve the issues with the error messages. However, this time around, I’m not receiving anything back. It simply puts me back to the command line .

I’m using ATOM on Windows. I’ve also tried CMDR and am having the same issue.

Any help would be greatly appreciated!

Thank you!

As promised, here is the result:

powershell

hi i make the same mistake all the time
the answer is indentation. look at line 18

the reason when you type “python3.9 ex21.py”
nothing happens is it runs your code and ends.
you want it to print but you never said what

hope this helps you now and in the future :grinning:

I think @tanbeast is close, but it doesn’t look like you have a problem with indentation. I think you missed a function at the bottom of the script that actually runs all of this.

But, there’s a more important issue that I see here. You see how you have “PRINT” on line 18? This tells me that you probably typed all of this code in at once and didn’t run it while you were working on it. What I mean is you did this:

  1. Read the code from my book.
  2. As you read it, type in all of the code 33 lines of code.
  3. Run it once you’re done.
  4. Nothing works.

This isn’t how I work on code though. I do this:

  1. Read the first 1-4 lines of code.
  2. Type in the 1-4 lines of code.
  3. Run the script.
  4. See the errors, they must be in the 1-4 lines of code.
  5. Fix everything by constantly running it and fixing everything.
  6. Once it’s working, go back to step 1.

I’m basically using the python interpreter to help me find errors as I work. I think what you should do is–and this will sound insane–delete this file and rewrite it using the steps I outline above. If you do that then you’ll find all these errors and also learn a lot about the kinds of errors Python gives you, but in small chunks that aren’t demoralizing.

1 Like