A Childrens Guide To Python Programming PDF
A Childrens Guide To Python Programming PDF
Python programming
By Yoseph Wondafrash
1. Printing text and creating variables
print("Hello world.")
print("\n")
print("I am learning Python.")
2
2. Calculations and random numbers
3
3. Number variables and adding comments
4
4. If statements
answer = input("Do cats bark? ") What does this program do?
if answer = = "no":
print("Correct") Why do you think two equals
else:
print("Wrong") signs are used and not just one?
Edit and Change the question being asked (and the answer
improve: too, if needed).
Start a program.
Programming challenge:
Create a program that asks a maths calculation and prints if
the user answers it right or wrong. Can you change one of
the numbers in it to a random number?
5
5. Arrays
veg = random.choice(vegarray)
print("Mashed",veg," on the ceiling.") What does this program do?
veg = random.choice(vegarray)
print("Boiled",veg," on the floor.") What is the purpose of the
veg = random.choice(vegarray) vegarray?
print("Stewed",veg," in the corner.")
veg = random.choice(vegarray)
print(veg," upon the door.")
Array - A list of values.
Edit and
Put more items in the array to make the poem more interesting.
improve:
vehicles = ["bus","car","train"]
print(vehicles[0])
print(vehicles[1])
print(vehicles[2]) Can you see what the:
vehicles.append("plane") .append, .pop,
print(vehicles) .insert and .remove
vehicles.pop(2) commands do?
vehicles.insert(2,"boat")
print(vehicles)
vehicles.remove("car")
print(vehicles)
Programming challenge:
Create an array to store a list of names. Add commands to: .append, .pop,
.insert and .remove names. Find out what the .sort() command does.
6
6. Functions
Change
the program so it shows the results of rolling
Edit and a six-sided dice instead. You don't need to put ""
improve: around the options because they are numbers.
Programming challenge:
Create a program that tells a user's fortune by calling (running) a
function two times which randomly picks a prediction from an array:
e.g. You will be given money.
You will become famous.
You will see an alien.
You will find a lost item.
You will score well in a test.
7
7. Iteration (looping)
password = "fish"
guess = ""
If = = means 'equal to',
while (password != guess"): what does != mean?
guess = input("Enter password: ")
if password = = guess: What does a while loop do?
print("Correct")
else:
print("Try again")
Programming challenge:
Create a program in which the computer sets the password as a
random integer from 1 to 100 and user has to correctly guess it.
Can you use: if, elif and else commands to give the user clue
(e.g. "Too high" or "Too low")? Can you add a variable which
counts the number of guesses (count = count + 1)?
8
8. Parameters and validation
Programming challenge:
Create a function that prints the biggest of two values. In the main
program below it, the user will input two integers and they will
be passed to the function as parameters.
Programming challenge:
9
9. Algorithms
Algorithm - An explanation of a the processes or instructions a program
carries out, usually described in a flowchart.
Programming challenge:
Create a simple version of a Snakes and Ladders game:
move function
Start
Press the
keyboard to roll
Set position = 0
Set dicenumber as a
random number Is
between 1 and 6. position yes Print a "Well
done" message
> 100?
position = no
position +
dicenumber Run move function Stop
no
Stop
Can you add more print commands to display what is happening on screen?
Can you make the game print the player's name at the end?
Can you add another player to the game whose position is stored in a variable
called position2? You will need to make the game let each player move in
turns. You could create a variable called finished which is set to 0 at the
start and changes to 1 when a player wins, forcing the game to stop.
10