Thursday, November 17, 2016

Divisibility Rules with Scratch

Elementary and middle school students benefit from knowing basic divisibility rules.  The four basic divisibility rules are:

A number can be divided by 2 if it ends in 2,4,6,8, or 0

A number can be divided by 2 if the sum of its digits can be divided by 3.  (Also helps students understand the difference between digits and numbers.)

A number can be divided by 5 if the number ends in 5 or 0.

A number can be divided by 10 if it ends in 0.

There are others, but these are essential.

If students are able to program a computer to follow the rules, then you can be pretty sure that they understand the rules.  Also, this program uses a mod operation, which is a cool thing for a middle school kid to learn.

Source code is here .  There are better ways to do this, I'm sure.

Friday, November 4, 2016

Transposition Cipher, Python

Kids who are motivated to learn a programming language will love Al Sweigart's books.  He's written four Python programming books, including a beginner game programming book and an intermediate game programming book.  They are freely downloadable, or you can buy printed copies.

I'm going through his Hacking Secret Ciphers with Python, which is a fun introduction to using Python to encrypt and decrypt messages.

This transposition code was pretty cool.  I want to teach this!  I also want to turn it into a Scratch program! 




Saturday, July 9, 2016

Richard Feynman and Teaching

From the  Farnam Street blog.  Excerpts from the book, "Genius : the life and science of Richard Feynman  by James Gleick."
 
Process vs. Outcome
Feynman proposed that first-graders learn to add and subtract more or less the way he worked out complicated integrals— free to select any method that seems suitable for the problem at hand.A modern-sounding notion was, The answer isn’t what matters, so long as you use the right method. To Feynman no educational philosophy could have been more wrong. The answer is all that does matter, he said. He listed some of the techniques available to a child making the transition from being able to count to being able to add. A child can combine two groups into one and simply count the combined group: to add 5 ducks and 3 ducks, one counts 8 ducks. The child can use fingers or count mentally: 6, 7, 8. One can memorize the standard combinations. Larger numbers can be handled by making piles— one groups pennies into fives, for example— and counting the piles. One can mark numbers on a line and count off the spaces— a method that becomes useful, Feynman noted, in understanding measurement and fractions. One can write larger numbers in columns and carry sums larger than 10.
To Feynman the standard texts were flawed. The problem

29
+3

was considered a third-grade problem because it involved the concept of carrying. However, Feynman pointed out most first-graders could easily solve this problem by counting 30, 31, 32.
He proposed that kids be given simple algebra problems (2 times what plus 3 is 7) and be encouraged to solve them through the scientific method, which is tantamount to trial and error. This, he argued, is what real scientists do.

“We must,” Feynman said, “remove the rigidity of thought.” He continued “We must leave freedom for the mind to wander about in trying to solve the problems…. The successful user of mathematics is practically an inventor of new ways of obtaining answers in given situations. Even if the ways are well known, it is usually much easier for him to invent his own way— a new way or an old way— than it is to try to find it by looking it up.”

It was better in the end to have a bag of tricks at your disposal that could be used to solve problems than one orthodox method. Indeed, part of Feynman’s genius was his ability to solve problems that were baffling others because they were using the standard method to try and solve them. He would come along and approach the problem with a different tool, which often led to simple and beautiful solutions.

Wednesday, July 6, 2016

LCM with Scratch

Source code here.  If anything, this is a good way to illustrate that using multiples to find LCM can be extremely time consuming, even for a computer.  The factoring method becomes much more appealing when faced with finding the LCM of 270 and 120.

By the way, it took Scratch 46 seconds to find the LCM of 270 and 120 using this algorithm.  It took Python about 2 seconds using a similar algorithm.





Tuesday, July 5, 2016

Histograms with Scratch, 20 coin tosses

A simple histogram is easy to make with scratch and you can use it to represent coin tosses.  Coin tosses are cool because most students have an ingrained belief that if you flip a coin 20 times, the results will always be close to 10 heads and 10 tails.   Actual results are frequently quite lopsided!  Code is here.


Monday, July 4, 2016

Finding the LCM with Python

Middle school students first learn to find LCM by listing multiples, then they learn to do it by factoring.

I started playing around on Python creating, what I thought would be, a really simple program to find LCM by listing and comparing multiples.  The goal would be to help students understand what LCM means before moving on to simpler ways to find LCM.

My method turned out to be REALLY convoluted and messy.  I just sat down and started typing and did absolutely no planning.

I ended up using TEN variables just to compare two sets of multiples.  It's a good lesson in balancing the "never give up until the problem is solved" mentality to the "quit and find a better way to do it" mentality. In this case, I should have quit, gotten out a sheet of paper, and outlined a better way to do it.

Incidentally....there is no LCM function in Python.  The simplest algorithm I've seen is the one linked above.

Sunday, July 3, 2016

Dividing by 10

Another iterative process that leads middle school students to a better understanding of  our base 10 number system.  It also lets them see the patterns that emerge with decimals when they divide by 10. 

If you run the program for them without showing them the code, most students, even beginners, will be able to program it assuming that they've had some practice with loops.

You might want to help them a little bit with join statements.

My version of the code is here.




Saturday, July 2, 2016

Fibonacci Series with Scratch

The Common Core State Standards encourage students to: Look for and express regularity in repeated reasoning.

 Designing programs that emphasize iterative processes help students recognize patterns and then think about ways to describe the patterns using mathematical operators and variables.

This Fibonacci series program would not be a good one to start with.  Probably a simple skip counting program would be better.   

There are many different ways to code this, and it's fairly challenging so it will keep advanced programmers engaged.  Again, start off my showing the program run, and then have the students do some pseudo-coding before they open their computers.

You don't necessarily need to use all of the "join" statements.  They can get confusing.    This is a simpler version that removes the extraneous join step.

Thursday, June 30, 2016

Coin flipping cat

One good way to start a programming project is to show students what you want them to build, then have them spend some time brainstorming and pseudo-coding before they even open their Chromebooks.

In this case, I will show them the coin flipping cat video,then lead a brainstorming session about how this program can be designed.  If the students are working in pairs or small groups, they can pseudo-code and brainstorm for 10 minutes and then we can spend 5 minutes sharing ideas.


My version of the code.

Wednesday, June 29, 2016

Atari Basic

When I was a kid, my dad got an Atari 800 and taught me BASIC programming.

First of all, I just saw online that an Atari 800 cost about $1,000 in 1980 which, at the time, was a shit-ton of money, especially for a computer that had (a max) of 48K of RAM and a 1.8 Mhz processor.  I remember that when we first got it, we could only load programs from a cassette tape. You could hear the program being loaded.  It screeched rapid fire morse-code through the TV speaker (there were no monitors), and it took about 90 seconds to load a program.  Later on, we got a 5 1/4" disk drive.  I forget what the disk capacity was then.....

Anyway, BASIC. Beginners All-purpose Symbolic Instruction Code. BASIC was perfect for a kid. It was so forgiving of bad programming.  First of all, you had to hit "return" after every line of code and it immediately told you when you used the wrong syntax. So, if you accidentally typed "prunt", you knew it immediately.

Also, Atari BASIC let you use the GOTO statement, which forgave a multitude of programming sins.  As a child programmer, the idea of a program being a logical group of individual subroutines just didn't click with me.  Most of my programming was a collection of "oh yeahs" and "oh waits."  GOTO allowed me to hop all over the place....all I had to do was type in GOTO 50 and the program hopped to line 50.  I could have the program jump from line 20 to line 200 and back to line 20, and as a result, I created programs that that were spastic and squirrely.  


   
When I returned to programming in college, I discovered that GOTO statements were no longer a part of the programming vernacular.  When I was a Freshman, my old Computer Science teacher, who freely smoked cigarettes in his office (he had tenure) and wore a black turtleneck like a yellow, crusty Steve Jobs, yelled at me for asking how to "GOTO" line 80.

My 17 year old son has my old Atari 800 and he loves playing Star Raiders .  I need to Hyperwarp my way over to Ebay and find another one and show it to my students....they will either be blown away by it or  extremely non-impressed.  I'm guessing the former. 

Tuesday, June 28, 2016

Word Scramble with Python

Something that 6th graders will enjoy and will be successful at coding.  The code is clunky but it's a good opportunity for kids to find ways to improve it.

As always, provide an entry point for the kids to start creating the program, and then help them as they run into problems.

A lot of "education experts" have been parroting the mantra that struggle is good.  That's been the big fad in education for the last couple of years, as if it was an astonishing discovery that you want kids to be able to work hard at something without giving up.  Yeah, struggle and perseverance is good, but every kid has a different tolerance level for how much struggle he/she is willing to deal with.  The best a teacher can do is figure out a kid's "zone of willingness to struggle," and then stretch that zone a little bit each day.

I've seen kids spend hours trying to fix a problem with a program.  I've seen other kids quit within a minute of encountering a problem.  I didn't instill those qualities in my students and I have no clue what made them that way.  Maybe it's their parents.  Maybe it's their genes.  Maybe it's the coffee they drink.

If  I am working with a quit-in-a-minute student, I can ask a good question and then push him to go 2 or 3 more minutes. That's an improvement.  At least he's not a quit-in-a-minute student anymore.  Ultimately, though, every student needs to experience some level of success in a coding class, so I need to make sure every kid is making progress, even if I have to give him an answer. Struggle without success, for many kids, is a guarantee that they will never pursue coding (or math) at any level.


Monday, June 27, 2016

Fibonacci AND functions

This was posted on the Python website, a cool little program to generate the first numbers of the Fibonacci Series.   So, with a simple 7 or 8  lines of code, you can teach kids how to define functions and teach them about the Series!


Sunday, June 26, 2016

Python Carrot Puzzle

I recently discovered that '^' does not mean 'to the power of' in Python.  I discovered this in quite a painful way while coding in a library. Librarians don't like it when you start yelling at your computer.  They get aggressive.  They get mean.  Some of them know Jujitsu.

It turns out that 3^2 is not 9.            3**2 is 9.

3^2 is 1.  That seems easy.  3-2=1.  

Well, 3^8 is 11.  Oh...so 3+8=11. 


*%*$!!     3^6 is 5!!!!!!!


Look at the pattern below.  What do you see?


Friday, June 24, 2016

Binary to base 10

This Scratch program would be extremely easy to teach to middle school students....except....for some reason, the developers of Scratch never included a general exponent operator block.  A simple x^y would have sufficed.  Instead, they only offer 10^x and e^x .

Scratchers have complained about this for years, but nothing has changed. 

So, a simple "turn a binary number into a base-10 number" program, which any 6th grader could write and understand, gets kind of complicated because the programmer needs to convert base 10 to base 2, which is easy for Algebra 2 students who knows logs, but not for 6th graders who barely have their heads wrapped around exponents.

Oh well. This will be a good opportunity to let the kids do some Python programming.  The scratch version is shared.


Thursday, June 23, 2016

Binary

There is no better "beginning of the year" lesson for 6th graders than a binary number lesson.

It gets students adding and multiplying (and enjoying it), it makes them feel smart, and it opens their brains to a whole different way of looking at numbers.  It also gives them a fundamental understanding about computers....for now (until Quantum computing becomes a reality), computers are just a complex system of on and off switches represented as ones and zeros.

Once you've shown them a base two system, have them compare it to our base ten system.  Have them identify the advantages and disadvantages of each.

THEN....expand out to the Aztec system (base 20) and the hexadecimal system (base 16).  Fun stuff! 

Oh...and no...9 times F is not "fleventy five."



Wednesday, June 22, 2016

Finding Ordered Pairs Game / Scratch

I was playing around creating a game with Scratch that gives a student 10 points for clicking on (or near, in this case) each ordered pair given by the "cat".

I started thinking about how I could help 6th graders create this game.  One thing I realized is that the program requires measuring the distance between two points, and sometimes those points have negative coordinates!!

California Common Core Standards don't require 6th graders to learn how to add and subtract integers.  I still teach these skills, though, because integer operations open up a huge world to young programmers.  One of the fallacies of state standards for math is that they claim that they want children to be creative and solve "real world" problems, but then they mandate a sequence of learning that doesn't lend itself to creativity or problem solving.


Programming is, far and away, the best way to teach kids how to hack away at problems and find creative solutions. It teaches a form of iterative troubleshooting that the Common Core standards claim to encourage.  With programming, the only tools a kid needs to display and develop his/her innate creativity is a computer and a basic understanding of arithmetic.  

I created two different versions of this program: one that uses the distance formula and one that just measures vertical and horizontal distance.



Monday, June 20, 2016

RaspberrySTEM Creator Kit

I've been having so much fun with RaspberrySTEM.  The author of the curriculum does an awesome job teaching programming concepts in very concise and manageable steps.

One example of his incremental approach is below.  He's teaching how to create game loops using an LED matrix (which reminds me of the  Coleco football  game from my childhood).


Sunday, June 19, 2016

Bar Code Math

A fun activity to get kids adding, multiplying, and dividing:

A UPC code has a built-in safeguard to ensure that it is always scanned correctly.  The Starbucks bar code below represents a 12 digit string:

7 6 2 1 1 1 8 2 3 3 1 1


If you multiply the 1st,3rd, 5th, 7th, 9th, and 11th by 3, you get 66:

3(7+2+1+8+3+1) = 66    (this would be a good opportunity to illustrate the distributive property)

If you find the sum of the 2nd, 4th, 6th, 8th, 10th, and 12th numbers, you get 14.

(6+1+1+2+3+1)= 14

When we add the two numbers together, the sum is 80 which can be divided by 10.  It turns out that most UPC codes follow this "divisible by 10" schema.  If a digit was scanned incorrectly, it would be highly unlikely that the resulting sum would be divisible by 10....if it wasn't divisible by 10, it would be flagged as an error and then re-scanned.


I've been skulking around Starbucks taking pictures of UPCs and the baristas are getting a little weirded out.    Every UPC I've checked in this store follows the "divisible by 10" protocol.   I better stop, though, before I get myself into trouble.


Saturday, June 18, 2016

Caesar Cipher: part 3

I got obsessed with perfecting this Scratch code.  I could have been working on a dozen other projects, but this one was bugging me.  Now it works like I wanted it to work.

It is shared on Scratch.






Caesar Cipher with Scratch

This is the new and improved version.  Again, I originally did this with Python and there are a couple of things that Python can do that Scratch can't so I had to find a different way.  A fellow Scratcher helped me deal with spaces and punctuation.






Friday, June 17, 2016

Caesar Cipher Using Scratch


I'm doing things backwards.  I'm learning from a great book called "Hacking Secret Cyphers with Python,"  by Al Sweigart. I took his Python code and converted it to Scratch.  Part of it, anyway.

I haven't figured out how to deal with spaces and punctuation yet.  With Python, it's easy.  I haven't figured out how to do it with Scratch.

Students love "secret codes" so I'm trying to figure out ways to integrate secret codes and code-writing into math class.  Encryption is all about math, so I'm experimenting with different ideas this summer.  This code is actually somewhat complicated. Not sure it would click with the average middle school kid.






Wednesday, June 15, 2016

Is it a prime number?

Below is a clunky Scratch program to determine if a number is prime.  Middle school students love prime numbers because they're somewhat mysterious and unpredictable.  When I say 'mysterious and unpredictable,' I'm referring to the numbers, but I suppose I could be referring to the kids, too.

Click on image to make it bigger.



This program introduces students to some cool concepts.  One concept is the modulo.  Instead of referring to a textbook definition of modulo, I usually give students some examples of mods and they tell me what it means:
12 mod 6 is 0
5 mod 4 is 1
8 mod 5 is 3
15 mod 6 is 3
50 mod 11 is 6
18 mod 6 is 0

If they have trouble, saying the word "remainder" usually derails their train of thought and gets them on the right track.  

This program starts with finding (initial number) mod (initial number- 1) .

It then loops while decreasing the divisor by 1 and checking each modulo for a zero.

 Yes, this is inefficient.  When it runs across a modulo of zero (as long as the divisor is not 1), it states that the number is not prime.

Another cool concept that kids are fascinated by is the fact that all of our encryption, all the secret codes that keep our bank accounts safe, depends on the difficulty in factoring REALLY large numbers.  Kids will see when they enter a 7 or 8 digit number that it might take a LONG time for the program to determine if the number is prime (or find one of its factors).  Our encryption relies on numbers with tens of thousands of digits, and even the fastest computers in the world would take years to factor them.

Below, I chose the number 7,465,001.  I had no idea whether it was prime, and it took the program about 90 seconds to find one of its factors:  5,437 
A nice challenge to give the students is to have them create a variable that takes on the value of the other factor and display that variable.



Tuesday, June 14, 2016

RaspberrySTEM Creator Kit

The creator of the RaspberrySTEM Creator Kit describes it as a "Hands on platform for learning programming and electronics."  I purchased the kit with the hopes of integrating it into my classes next year.

After playing with it for a few days, I must say:   IT IS AWESOME!

First, imagine an electronics kit that you get to assemble yourself.  Yes, you GET TO.  It's fun! The instructions and diagrams are extremely clear and easy to understand and written by someone who understands his audience.  He knows that he's not writing for Berkeley engineers; he's writing for students and teachers that may or may not have experience with electronics and programming.

The kit uses Raspberry Pi as its "processing" backbone and a large set of components (a breadboard, lots of wires, LEDs, resistors, an accelerometer, an LED display, an HDMI cable, buttons, a speaker, and a really cool plastic case to house the whole thing.)

Then imagine small, easily digestible lessons that walk a student carefully through the process of designing circuits and then programming them with Python.  The lessons are logical and incremental and FUN!  Below is the circuit and the code used to test the LEDs on the Simon game.   





Instead of just telling students, "Build this, and type in this code," the author  walks the student through the process of outlining the code necessary to play the game (creating psuedo-code), assembling the button layout on the breadboard, coding and testing the buttons, assembling the LEDs, and then coding and testing the LEDs.  He then walks the student through manageable, incremental steps of programming the game. 

Simon is just one project of many that the author has created.  

RaspberrySTEM is a great way to teach students how hardware and software interact and it will definitely bring out the inventor in elementary school, middle school, even high school students.  I'm really excited to use this next year.  I need to make sure that I thank our district's EdTech director for telling me about it!! It was exactly what I was looking for!  Thanks, Brian!

Monday, June 13, 2016

Guess the number....Greater than, less than

A fun scratch program to help reinforce greater than and less than symbols.  There are many ways to challenge students to improve this game.  One way is to ask students to add a message telling players that their guess is close (within 10) of the number.


Sunday, June 12, 2016

Skip Counting with Python

For highly motivated teachers who want to teach 6th grade Python coding!


Saturday, June 11, 2016

Skip Counting

I can never assume that ALL of the 6th graders know their multiples up to 12 x 12, but most of them do.  It’s an essential skill that makes life easier, so I make a point to ensure EVERY student can skip count by (at least) 12.   Early in the year we do some skip counting programming and then, later on, use it to write programs to find LCM.
The students enjoy writing skip-counting programs and I like to share their programs with teachers in lower grades when they are skip counting.  My students feel good knowing that they are writing programs to help students in the lower grades.  And lower grade kids then have a chance to learn a little bit of coding, too!
I usually start them out with something like this (using scratch):


I then enhance the lesson by having students:
  • change the speed at which the cat counts (there is so much room for learning here….am I sure that ALL of my students understand that 0.315 of a second is SMALLER than 0.6 of a second?  )
  • Have the students enhance the code a little and have the cat ask how high he should count to.
  • For more advanced students, use MOD to determine if the “count to” number is a multiple of the given number.  If it’s not, how would the cat help the user modify his/her number?

Friday, June 10, 2016

MASH with Scratch!

A few of my clever students figured out the best way to play MASH…they coded it using Scratch!

As much as I hate the game….I was impressed by what they came up with.
This was the best/simplest version of the code that a few 6th graders created.