#Python for Pupils – The first Project

Well, I am about to embark on my first teaching mission concerning actual coding. Since none of my pupils have ever coded before and some do not even have a proper computer at home, only smart phones and tablets, I will start with a very basic project.

What I have in mind is a simple prime number checker, since all that is needed for it is some input (always good to have some interaction between the user and the machine), a loop and a fork, plus some basic mathematical operations with which my pupils are actually familiar with.

So apart from learning basic coding, they will also see a basic real-world application of code and (since they are German native speakers) they will also (hopefully) get the message that learning English is important. After all: All common coding languages use basic English words and syntax. No English knowledge, no coding. That’s just it.

This is the code I came up with. It works up to a certain point but glitches out, once the numbers get too high. Never mind that flaw, for demonstrating basic principles of programming, it is sufficient.

theNumber = input("A number, please: ")
x = 2
while x <= theNumber:
    leftover = theNumber % x
    if leftover == 0 and x != theNumber:
        print "Not a prime, divides by", x
        result = theNumber/x
        print theNumber, "divided by", x, "is",  result
    if leftover == 0 and x == theNumber:
        print theNumber, "is a prime number"
    elif leftover != 0:
        x = x+1

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: