Python For Kids
Python For Kids
(Ages 10-16)
0 Installation
1 Basics
Karan was born on January 2012. His sister Priya was born on
February 2016.
a) How old are Karan and Priya in May 2019? How old will they
be in December 2030?
b) What's the age difference between Karan and Priya?
c) Let's model these as equations:
Age(Karan) = Current Year – 2012
Age(Priya) = Current Year – 2016
Age Difference = Age(Karan) – Age(Priya)
= (Current Year – 2012) -
(Current Year – 2016)
= 2016 – 2012 = 4
d) Let's write some Python code to compute the above. Which
are the constants and which are the variables?
4 If-Else
Modify the flowchart (on pen and paper) so that we first check
if guess equals selected number. Change your program based on
a modified flowchart.
7 Function
9 For Loop
On pen and paper, find the sum of all even numbers from 20 to
50. How long did it take you to find the answer?
Let's now write a program so that the computer can give us the
answer quickly:
total = 0
for i in range(20, 51, 2):
total += i
print(total)
11 Make a Graph
Run the program marks_barchart.py. What can you make out from
the chart?
We can multiply or
divide these numbers to
get a new range. This
is called scaling.
13 Hidden Word
15 Hungry Baby
In this game, you produce food for the baby and put it on a
plate. The baby consumes food from the plate. Computer
scientists call this type of problem the Producer-Consumer
Problem.
How many items can you feed the baby? Run the program
hungry_baby.py to find out. Answer the following questions:
a) How many coins do you have when the game starts?
b) How does the baby choose what to eat next?
c) Once fed, how long does the baby wait before crying again?
You can increase this if the game is too fast for you.
d) When the baby is fed, how many coins do you earn?
e) When or how does this game end?
c) Take your school mark sheet for last year. Use Matplotlib
to plot a suitable graph of the marks.