At the time of writing in the UK, people are arguing and deciding whether to vote to stay in the European Union or vote to leave. The code below is broken (like the EU?) but is worth fixing (like the EU?).
When fixed it will let you have your own referendum by passing the micro:bit around the room for each person to press A or B. If you touch pin 0 for 3 seconds it will keep showing you the result of the vote, until you reset the micro:bit for another vote.
There are three deliberate errors:
A syntax error is stopping the code from running at all. You’ll see an error message telling you which line the error is on when you attempt to run the code. Compare that line with similar lines to see what’s missing.
A runtime error doesn’t stop the code from running but does make it crash when it gets to a certain point in the code. Compare line 23 with 25, 27 and 29 and you’ll find a variable spelt incorrectly that causes a runtime error.
A logical error is making your code behave incorrectly: it does exactly what it’s told to do but its been told the wrong thing. See what happens when you vote for B and try to work out what’s gone wrong.
- See if you can find and fix all three errors to make your own micro:vote counter:
awesome post. Thanks for the post.
People should know why should they learn python
for more info see http://bindit.in/why-should-you-learn-python-programming-language/
Appreciate ! Keep such innovative postings.
Python Web Development
Wow – love this simulator. Haven’t managed to get into coding the micro:bit with anything other than the block editor up til now – this is LOADS better!
Here’s my first program, part of a Christmas display I’ve stuck on my classroom door here in Cambodia:
https://create.withcode.uk/python/NP
Press ‘A’ to announce the scroll the words of the angel.
Press ‘B’ to play ‘Away in a manger’ one note at a time (had to add the durations to every note, doesn’t seem to ‘hold’ the previous value whilst playing single notes otherwise – bug or feature?)
Q. How do I press A+B in the simulator?
I love your Christmas door display – thanks for sharing.
I’ve added a button to let you press both A and B at the same time to the simulator – thanks for the suggestion.
I don’t know about the bug / feature for playing notes – I’m in the process of updating the simulator to attempt to keep up with the new features of the micropython code (e.g. speech) so I’ll look into it.
Merry Christmas 🙂
Speech would be great. I did try the speech library but it said not found. I then tried copying it across to the ‘official’ microbit editor – the code compiled but then the micro:bit said it was out of memory 🙁