Thursday, October 22, 2015

Python for Kids

I am a believer that kids should start early on programming.  I started my son with raspberry pi and he showed a lot of interest in Scratch programming. That was relatively easy for him. I find that modern days programming is much easier than before. No need to check or track the if statement, for statement etc.... The editor is even graphic base and he just need to drag and drop. Everything comes with graphics user interface. He can easily create a few games for himself.

Now that his major exam is over, I started him with Python as I read that Python is a relatively easy book.



I download the program from this website. I installed the program on Mac while he installed on another windows machine. Everything was very smooth sailing. In fact, perhaps he could have done that all by himself. The next question is, how to teach him the program, as I don't have much time to do coding anymore. So, I took up a promotion from Udemy and sign up tthe "Python for Beginner" course for $10. I am sure that there are other good courses too.  To be fair, the program is quite good, easy to understand. But, my son just skip everything!

He did those exercise provided by the course. He just wants challenge. So, I told him to write a program to generate as many prime number as a user wanted. Immediately he came up with this program:

-------first program---------------
import time
print('How many prime numbers would you like me to list for you?')
limit=int(input())
t1=time.time()
prime_numbers=[2]
a=2
numbers=1
while True:
    a=a+1
    b=prime_numbers[0]
    x=0
    while True:
        ans=(a/b)
        if ans==int(ans):
            break
        b=b+1
        if a==b:
           prime_numbers.append(a)
           numbers=numbers+1
    if numbers==limit:
        print(prime_numbers)
        break
t2=time.time()
print('I took %s seconds, definitely faster than you!' % (t2-t1) )

----------------------

He picks up the language and become familiar with this much faster than I do. I did not touch programming for many years and I was struggling to complete the program. I told him about the concept of programming time and taught him about algorithm that he did wrongly above. Just 30 minutes later, he rectify with this version which is much faster than the previous one:

 --------------faster version-------
import time
print('How many prime numbers would you like me to list for you?')
limit=int(input())
t1=time.time()
prime_numbers=[2]
a=2 #a is the number to be tested
numbers=1 #number is the no. of numbers in the list
while True:
    a=a+1
    x=0
    d=0
    for y in range(0,numbers):
        c=prime_numbers[x]
        ans=(a/c)
        if ans==int(ans):
            break
        else:
            d=d+1
        x=x+1
    if d==numbers:
        numbers=numbers+1
        prime_numbers.append(a)
    if numbers==limit:
        print(prime_numbers)
        break
t2=time.time()
print('I took %s seconds, definitely faster than you!' % (t2-t1) )

--------------faster version-------
What I want to share here is not about the achievement. But about how fast younger generation can learn. They no longer look at books.  As you notice, he use "list". For me, I was worrying whether he knows how to use that. I mentioned "list", he found that from his book, and "tah-dah".... 30 min later, the first program was done using list.

While he completed the faster version in 30min, I was still struggling to debug mine. So, lesson learned, we parents should not write program with them.  But what we can contribute is the algorithm part.

So, I challenged him to write a multiplication training program for his sister. He breezed through that and came up with the following:

--------------------
import time
import random
import pickle
from tkinter import*
def start_now():
    print('3')
    time.sleep(1)
    print('2')
    time.sleep(1)
    print('1')
    time.sleep(1)
    print('START!')
    t1=time.time()
    score=0
    for x in range(0,10):
        a=random.randint(2,9)
        b=random.randint(2,9)
        ans=a*b
        print('_____')
        print('  %s' % (a) )
        print('x %s' % (b) )
        i=int(input())
        if ans==i:
            score=score+1
    t2=time.time()
    y=t2-t1
    y=round(y,2)
    if (t2-t1)<=30 and score>8.9:
        print("Not bad, you took %s seconds" % (y))
    else:
        print("You took %s seconds, better luck next time" % (y))
    print("Your score is %s" % (score))
    with open("progress.txt", "a") as f:
        f.write("On %s:\n" % (time.asctime()))
        f.write("-ykh completed the drill in %s seconds\n" % (y))
        if score==10:
            f.write("-ykh got all correct! :)\n")
        else:
            f.write("-ykh got %s correct\n" % (score))
        f.write('\n')
tk=Tk()
btn=Button(tk,text='start drill', command=start_now)
btn.pack()

--------------------
Luckily I  did not kill his interest by giving him a class, or insist him to go through step by step all those functions through Udemy courses. Millennium kids really learn programming very differently. So, we just show the way.  Running out of idea, I direct him to this book: 



I think I better get lost and leave him alone when he plays with his new play ground using Python. I am sure he will like minecraft and get a lot of ideas on what to do from the book below. So, I hope this post gives you an idea if you want to teach your kids programming.





Wednesday, October 7, 2015

Haze - How to protect ourselves?

In previous post, I explained about Haze. Now, let's talk about what action we can take to protect ourselves. Here are the actions I took

(1) Wear N95 Mask when you are outdoor
During Haze season, N95 mask should be used instead. Check out this website from MOH in Singapore For those of you in US, if you are traveling to South East Asia between Aug and Oct, get yourself ready with N95 mask from the 3M N95 mask ">Amazon link here, especially these:



Children may require smaller size mask meant for children:


During Haze season, these items may be out of stock as most people will buy last minute. On the other hand, you don't want to stock these too much as the items have shelf-live of few years.

(2) Stay in air-con room as much as possible
Air con room has better air quality than outdoor during haze seasons. When the air is cooled down, condensation takes place as the particle matter may be trapped in water droplet.

(3) Get yourself an air purifier
Don't buy last minute. Get one ready if you are living in South East Asia. If you have allergic and other chronic health issue,there are professional equipments such as those from IQ Air. My boss bought one of these. But it's bulky and expensive. May be few thousand dollars.

There are many portable air purifiers around. See the list provided by National Environmental Agency in Singapore. But this list may not cover those cheaper and more affordable consumer oriented purifier that we find in electronic department. You may want to be careful as not all devices are effective. In particular, you may want to buy a "hepa filter" based purifier (not hepa type filter). The good news is Consumers Association of Singapore (CASE) had conducted the test on those. Check out their results that I downloaded for your convenience below:

2014 test


Clik here for 2013 test

Based on the above, I bought one from Novita (NAP611) and my second one from Delonghi (AC150). Considerations (not in sequence) are (a) whether the device is effective and to me, it is important that the device is listed at least in one of those websites above (b) capacity of the device, i.e. the coverage area (c) Performance as listed above (d) a sensor that indicates air quality (e) price

I know that both the devices I bought are effective because the sensor is pretty accurate in sensing the air quality. When the air is bad, the light indicator correctly indicate those. For example, if I cook, or if I open the door or window, I can see reaction from the device.

Haze - What you should know

If you stay in South East Asia, there's one man-made disaster that you probably would be familiar with, i.e. Haze. Take a look at the following photo. Visibility is low. I did not experience this during my childhood time in the 70s. If I remember well, we did not experience much of this in the 80s too.

What causes the haze? You can read the details from Wikipedia here. In short, The haze is largely caused by illegal agricultural fires in Indonesia. Burned land can be sold at a higher price illegally, and eventually used for activities including oil palm and pulpwood production. Burning is also cheaper and faster compared to slashing and cutting using excavators. Obviously, these are selfish economy activities who disregard the health of public. While the source is from Indonesia, it is believed that many foreign companies such as those from Malaysia and Singapore are also involved.

Comment from a Indonesia politician saying that Singaporeans and Malaysian should be thankful for 11 months of good quality air and not complain much during the 1 month of Haze period is totally irresponsible and absurd. The problems had been for at least two decades, and we do not see material attempt to resolve the issue, except that Singapore has local law to punish Singapore companies responsible for forest fire in Indonesia. I heard that those bureaucrats in Jakarta are enjoying blue sky every day and I can understand that there's no urgency in them to solve the issue. So, sadly, I believe the problem will persist for at least few more decades.

Unfortunately, many people do not understand the precaution well. While most of us in Singapore are well informed, I don't see the same level of understanding in other parts of South East Asia. For example, I am very shocked to see Indonesia's preseident, Jokowi gave interview after visiting Haze affected area wearing surgical mask. Many people in Malaysia wears surgical mask too. But do you know that surgical mask is not effective in protecting you?

From what I read, one major harmful particles in the Haze are particle matters less than 2.5micron, or PM2.5. These fine particles are even smaller than bacteria or virus.

PM2.5 is fine enough to enter the bloodstream, and being exposed to PM2.5 increases the risk of death in general and from heart and lung illnesses – and for every 10-microgram increase in annual PM2.5 concentrations, the added risk of dying from overall causes, cardiopulmonary disease and lung cancer goes up 4 per cent, 6 per cent and 8 per cent respectively over a 16-year period.

You may want to check out more information from the following websites

(1) Environment Protection Agency (USA) website about pollutant in particular "particle matter"
(2) FAQ on Environment Protection Agency Website
(3) Health Exchange Website about PM2.5
(4)Singapore National Enviornment Website on Haze : Haze reading in SG available here
(5) Malaysia Air Pollutant Index - Department of Environment

Please read the next post about what action can we take to protect ourselves.