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.
Hi, is there an error on the conversion of “forever if”. It should be:
while true:
if [condition] :
…
Finally got around to correcting the error on the “forever if” section.
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…!).
Oops… [blush]
I’ll correct the sheet and upload again.
Looking for conversion for “key pressed?” I don’t want the program to wait for a key press such as raw_input
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().
Reblogged this on Hollinswood Primary School Blog and commented:
This will be so useful for students in Yr 6. Thanks to the rPi Kitchen
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.
Instead of: count = count -1
you can do: count -= 1
And instead of: myScore = myScore + 1
you can do: myScore += 1