Friday, November 1, 2013

Debugging Part 3 - Pumpkin Carving

     So, as you remember in the last article, our program had an error. When you get accustomed to them, you can figure out what they are saying. It's the last line that gives you the reason the program crashed.

Traceback (most recent call last):
  File "C:/Python33/Pumpkins.py", line 79, in <module>
    easygui.msgbox("A pumpkin with", Pumpkin.eyes, "eyes, a", Pumpkin.nose, "nose, and a", Pumpkin.mouth, " ", Pumpkin.expression, ".")
TypeError: msgbox() takes from 0 to 5 positional arguments but 9 were given

     Let's take a look at the last line.

TypeError: msgbox() takes from 0 to 5 positional arguments but 9 were given

     So, EasyGUI messagebox had too many variables to work with, or something. I'm not sure, so let's just figure it out. Let's start by changing the msgbox into a print statement.

print("The pumpkin has", Pumpkin.eyes, "eyes, a", Pumpkin.nose, "nose, and a", Pumpkin.mouth, " ", Pumpkin.expression, ".")

     Did that work?

Time to carve some pumpkins!
First things first...
The pumpkin has Fire eyes.
Okay, let's do the nose.
The pumpin has a Arrowhead nose.
Now, the mouth! But first...
The pumpkin has a Smile .
Now...
The pumpkin has a Round mouth.
Here's your entire combination:
The pumpkin has Fire eyes, a Arrowhead nose, and a Round   Smile .


     Really, that was it? Wow. It pays off to actually read the errors, doesn't it? There must be some way around that arguments thing on EasyGUI, but that's probably gonna be extremely hard to find. Well, I guess Halloween is over, but if I do search for that way around, Halloween will spring back up!
     I challenge you to find a way around the error while still using EasyGUI (if that's even possible)!

No comments:

Post a Comment