10
Python Lesson 3 1

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

Embed Size (px)

Citation preview

Page 1: 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

Python

Lesson 3

1

Page 2: 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

StarterCreate 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.

2

Possible Solution:

Page 3: 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

3

Objective of the lessonWrite 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.

Page 4: 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

4

• 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.

Homework

Page 5: 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

5

What will this code do?import random is used tell Python that you want to be

able to use random numbers in your program.

random.randint(1,3) will create a random integer between 1

and 3.

Page 6: 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

6

• 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.

Rock … Paper … Scissors game

Page 7: 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

7

For loopsA For loop looks as follows:

number is a variable used to count.

range is a function which sets the upper and lower limits; for

instance range (10) would count from 0 to 9.

Page 8: 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

8

Try this outCreate 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 32 times 3 is 6 3 times 3 is 9…etc

Possible Solution:

Page 9: 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

9

While loopsA While loop looks as follows:

while starts a loop which will

continue until the condition has

been met.

Page 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

10

Try this outCreate 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: