Python Worksheet 3 Selection

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Worksheet 3 Selection

Introduction to Python

Worksheet 3: Selection
Task 1
1. Which operator will you use? Complete the selection statement by inserting the correct
operator for the description shown. The first one has been completed for you.

Operators to use are: ==, !=, >, <, >= and <=

description IF statement

colour is red IF colour == “red”

mark is 50 or more IF mark 50

water is hot IF water “hot”

account balance is less than zero IF balance 0

battery remaining less than or equal to 20% IF battery 20%

light is not green IF light “green”

quantity in stock is 10 or less IF qty 10

age is under 18 IF age 18

amount due is greater than zero IF amount 0

no lives left IF lives 0

2. Put these statements in the correct order, making sure your syntax is correct for a
SELECTION statement in Python. Hint : two very important parts of the selection syntax
has been omitted

print("welcome to the Club")


print("Sorry, you're not old enough to join yet")
age = int(input("please enter your age "))
else
if age >= 14

Test your answer in Python

1
Worksheet 3 Selection
Introduction to Python

Task 2
1. Write a program that might be used inside a police speed camera. Save your program
as SpeedChecker.py

The requirements for the program are:

 It must accept the driver’s speed as input.


 If the speed is 75mph or over, a message “Issue speeding fine” should be printed
 Otherwise it should print “No action”.

Make sure you comment your program.

2. The Police have decided to ‘issue warnings’ to drivers whose speed is measured as
between 60mph and 75 mph. Extend and amend your program to reflect this change.

2
Worksheet 3 Selection
Introduction to Python

3. What input values will you use to check that your program works correctly?

Extension Task
Extend the program to check that the speed entered is a reasonable value. The speed
reading should not be less than 5mph.
Test your program to make sure it works as expected.

You might also like