jg789
Posts: 3
Joined: Wed Nov 08, 2017 6:41 am
Occupation: Student

Python eerror

Postby jg789 » Wed Nov 08, 2017 7:04 am

What does this error mean and how do I fix it?

Image

Teacher says it's not an important line anyway and I deleted it, but then got lots more just like it. IS this the broken code that everyone is getting? According to this forum?

Thanks for explaining it to me!

bfinio
Expert
Posts: 302
Joined: Mon Aug 12, 2013 2:41 pm
Occupation: Science Buddies Staff

Re: Python eerror

Postby bfinio » Thu Nov 09, 2017 8:02 am

Hi jg789,

Edit: my original post is below, but it does look like you are running the old version of the code. We posted an updated version of the code that we believe will fix the spacing errors. Can you try re-downloading the code from https://www.sciencebuddies.org/science- ... #materials, run it and see if you get the same errors?

Original post:

Thank you for posting a screenshot - several users have reported issues with this code, but no one has gotten back to us about the exact error messages they were seeing, so it has been difficult to troubleshoot.

Python uses indentations to organize code. One "indent" is equal to four spaces. So, for example if you want print statements inside an if/else statement, it should look like this:

Code: Select all

if x == 1:
    print("Stuff")
else:
    print("Other stuff")


Nested code must be indented in multiples of 4 spaces (4, 8, 12, 16...). If something is off by just one space, that will cause an error.

Looking at your screenshot - somehow, the spacing on all those print statements inside the else statement got really messed up. Everything immediately below the else: should be indented 8 spaces. Below is a screenshot of what the original code looks like on my computer. Notice how the print statements are all nicely lined up with each other. So - we need to figure out how these spaces got messed up on your computer but not mine.

Can you let me know:

- Did you edit the code at ALL after downloading it? Or did it look like that as soon as you opened the file?
- What day did you download the code? We uploaded a new version of the code on October 31st that I thought would fix the spacing issues. If you downloaded the code after that, then clearly there is still a problem.

code-screenshot.pdf
(48.32 KiB) Downloaded 9 times

jg789
Posts: 3
Joined: Wed Nov 08, 2017 6:41 am
Occupation: Student

Re: Python eerror

Postby jg789 » Thu Nov 09, 2017 9:23 pm

I had downloaded it about 2 weeks ago, had the problem and tried to figure it out. Since you said it was fixed, I just downloaded it again and almost exactly the same problem, only the lines are a little different. Where they should line up, they don't.

I'm worried now that this is too hard for me. If an expert can't make it work, then maybe I can't. I'll think of something easier for the fair.

bfinio
Expert
Posts: 302
Joined: Mon Aug 12, 2013 2:41 pm
Occupation: Science Buddies Staff

Re: Python eerror

Postby bfinio » Fri Nov 10, 2017 5:53 am

hi jg789 - don't give up! It isn't your fault that the code isn't working. We put all those extra "print" statements in there to explain what the program was doing as it ran, because previously, a lot of students were just running the program without really understanding what it did. However, apparently something about the spacing on those print statements is messed up for some people but not others. You can easily comment out statements that are giving errors and then the code should run fine. To comment out multiple lines at once, highlight them in IDLE, then from the top menu select "Format -> Comment Out Region."

If you want, you can also email us at scibuddy@sciencebuddies.org with the subject line "Python Code", and get in touch with me directly. We can send you an older, working version of the code without all the extra print statements (the forums won't let me attach Python files).

Thanks for your help with troubleshooting!

Ben

amcfee
Posts: 2
Joined: Wed Nov 15, 2017 11:50 am
Occupation: Parent

Re: Python eerror

Postby amcfee » Wed Nov 15, 2017 11:51 am

If anyone gets this to work, my daughter would like to try the project. If somoene could tell me how?

bfinio
Expert
Posts: 302
Joined: Mon Aug 12, 2013 2:41 pm
Occupation: Science Buddies Staff

Re: Python eerror

Postby bfinio » Wed Nov 15, 2017 12:46 pm

Hi amcfee - we have uploaded new code to the site that should be working. Can you try downloading the code (if you downloaded it a few days ago, make sure to re-download the new version) and let us know if it works?

amcfee
Posts: 2
Joined: Wed Nov 15, 2017 11:50 am
Occupation: Parent

Re: Python eerror

Postby amcfee » Thu Nov 16, 2017 5:41 am

Thanks bfinio, but she downloaded it and tried it before she went to meet the bus this morning and she said it still has indent errors.

bfinio
Expert
Posts: 302
Joined: Mon Aug 12, 2013 2:41 pm
Occupation: Science Buddies Staff

Re: Python eerror

Postby bfinio » Thu Nov 16, 2017 6:34 am

Hi amcfee - if you email us at scibuddy@sciencebuddies.org, I can send you an older version of the code that we know is working.

jg789
Posts: 3
Joined: Wed Nov 08, 2017 6:41 am
Occupation: Student

Re: Python eerror

Postby jg789 » Fri Nov 17, 2017 7:30 am

FYI, it's still broken.

Image

I followed the advice in a nother comment and just deleted the print statements.

bfinio
Expert
Posts: 302
Joined: Mon Aug 12, 2013 2:41 pm
Occupation: Science Buddies Staff

Re: Python eerror

Postby bfinio » Fri Nov 17, 2017 9:19 am

Hi jg789 - thanks for posting that screenshot. We appear to have tracked this down to a bizarre Windows/Mac issue. The original code was written on a Mac and I edited it in Windows. In your screenshot, the two "print" statements that are indented one extra space were written by the original author (Howard Eglowstein) and then I edited the text. Although the spacing is correct on my machine, it is clearly messed up on yours. We will re-upload a version that was only ever edited on a Mac, and hopefully that will resolve the issue. Thank you everyone for your bug reports!


Return to “Grades 6-8: Math and Computer Science”