You are on page 1of 10

Python

Lesson 3

1
Starter
Create a program which will ask people to type in
the alphabet. It should show a message to see if
they typed it correctly and a different message of
they didn’t type it in correctly.
Possible Solution:

2
Objective of the lesson
Write simple programs using Python.

• All of you will:


– Use the random function in your programs.
• Most of you will:
– Use For and While loops in your programs.
• Some of you will:
– Create simple games using Python.

3
Homework
• Everybody should complete Task
1 to plan the steps to play a game
called “Guess the fruit”.
• Some of you may also want to get
the extra marks by completing the
extension activity.
• This homework is due in next
lesson.
• Make sure you have written your
homework clearly in your planner.

4
What will this code do?
import random is used tell
Python that you want to be
able to use random numbers in random.randint(1,3)
your program. will create a random
integer between 1
and 3.

5
Rock … Paper … Scissors game
• Tell user to enter either rock, paper or scissors.
• Save their response in a variable.
• Generate a random number from 1 to 3
(1=rock,2=paper, 3=scissors)
• Compare the user’s selection and
the computer’s selection
• Display who wins.

6
For loops
A For loop looks as follows:
number is a variable range is a function which sets
used to count. the upper and lower limits; for
instance range (10) would
count from 0 to 9.

7
Try this out
Create a program that will ask the user to enter a number and then
use the “For” loop to show the times table for that number; for
instance if they entered a 3 then it will display:
1 times 3 is 3
2 times 3 is 6
3 times 3 is 9…etc
Possible Solution:

8
While loops
A While loop looks as follows:

while starts a loop


which will
continue until the
condition has
been met.

9
Try this out
Create a program that will ask how many numbers you want
to add together. It will then ask you to enter the numbers
(adding them to the previous total each time) and then once
the loop has completed, display the total of all the numbers.
Possible Solution:

10

You might also like