Saturday, February 18, 2017

Is it Prime? - Python

A fun experiment to conduct with students is to compare how fast a Python can determine if a number is prime versus how fast Scratch can do it.

Below is (clunky) Python code:


I checked to see how fast the Python program could determine that 7,465,001 is not prime.  It did it in about 7 seconds.  It took Scratch about 90 seconds to find a factor.  Ask the students why they think Python solves the problem 13 times faster than Scratch.   Their answers will interest you and give you insight as to how they understand computers and programming.

Another learning opportunity for students is to see how creating a program with Scratch makes it much easier to program with Python.  If they created the "Is it Prime" program on Scratch, they will have solid pseudocode to write  the program in Python.

No comments:

Post a Comment