Scratch -to- Python Conversion

Scratch to Python conversion sheet - click for a PDF file

Scratch to Python conversion sheet – click for a PDF file

Just as you get used to one programming language, the goalposts change and you need another one! This little guide sheet, on two A4 pages, covers the basics of using variables, decisions, lists and loops.

It has been written for Python 3 (the most commonly encountered difference is the need to put brackets around bits that need printing).

I’m going to keep a printed version with me as I’m sure it’ll be useful for explaining the different ways of constructing decisions and loops.

If I get the time, I’ll create pages 3 & 4 – perhaps to cover using GPIO within Scratch and Python.

Python-Scratch Conversion


11 responses to “Scratch -to- Python Conversion

  1. Hi, is there an error on the conversion of “forever if”. It should be:

    while true:
    if [condition] :

      • That’s awesome. Scratch 2 doesn’t have ‘forever if…’ blocks though, you need two separate ‘forever’ and ‘if’ blocks instead. Having said that, the Python conversion wouldn’t change 🙂

      • I’m working on the Pi with the older offline version so hadn’t seen this. I nearly wrote in my comment that I’d do it with the “forever” and “if” blocks as it seemed a little clearer. Now I’m pleased to see that they’ve made it necessary. Thanks for your feedback – it’s appreciated. If you feel I’ve left anything out I’m happy to add it in. I’m working on the Scratch, Python, PICAXE version (and just noticed some glaring errors). Need more sleep (and a little less assessment/marking to do…!).

    • A good point – it’s a useful function to have. I’ve heard that the pygame module has what you need, but I haven’t tried it yet. I needed something similar for my Ascii Photobooth, but in the end time was short so I used a gpio input with a push switch. If I find anything I’ll post it here.

      • I was able to get it to work using pygame module, however in order for the code to work it has to run in a graphic window, which I don’t need. The code I used was pygame.get.key_pressed().

    • I have another sheet which also covers the GPIO commands for the Raspberry Pi using both Scratch and Python (and also includes the PICAXE Basic commands). I think I need to make a version without the PICAXE as that’s probably more useful for secondary GCSE Electronic Products.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s