Programming Technique - Python 1 - Workbook
Programming Technique - Python 1 - Workbook
Python 1 section
Name:
Class:
• Title: Programming technique – Python 1
• Key Words: logic errors, syntax errors, run time errors, constants,
variables, data types, iteration, selection, sequencing.
Python Introduction
Starter
activity
• Create a folder in your area
named: Python.
Python Introduction
Lesson objectives…
KEYWORDS:
Syntax error – where you’ve broken the rules of the language.
print(“Hello year 7)
print(“Good bye”
GLOSSARY KEYWORDS:
Variable: A location in a memory Constant: A location in a
where data is stored. It can be changed memory where data is stored. It
while the program is running. cannot be changed while the program
is running.
Definitions:
Syntax: the order of instructions
or commands.
Value
film = “Lion King”
“Jumanji”
print (film)
Displays the
Assign film as value of the
a variable variable film.
which stores
the value.
Demonstration
food = "_____"
print(_____)
3) Ask the user for their favourite film. Display “I also
like watching”, film. E.G:
Paste your code below:
Q3 helpsheet
food = _____("_____")
print("I also like", _____)
Test phase
https://www.youtube.com/watch?v=jhVu
yveJMgA&list=PLCiOXwirraUBO3Z2dxnIfu
NDspmJmorJB
Data types
Lesson objectives…
Example:
age = str(age)
Demonstration:
Age Integer
House address
Name
Weight
Price
Is 5 == 5
9. Ask the user for 2 numbers then divide the first number by the
second number. Display the answer. To divide numbers use /
Paste your code below:
Q9 helpsheet
width = int(input("________"))
______ = int(input("Enter a height"))
area = _____*_____
print("The area of the rectangle is", _____)
11. Asks 2 users for their weight, calculate the average weight of
the 2 users.
Paste your code below:
Q11 helpsheet
Operators
Lesson objectives…
Understand arithmetic operators.
Demonstrate using operators to solve problems.
Use operators to solve a real-world situation.
Demonstration:
number1 = 10
number2 = int(input(“Enter a
number”))
answer= number1 * number2
print(answer)
(Floor
KEYWORDS: Addition, subtraction, multiplication, division, modulus, exponent.
division)
Consolidation
• Go on
• www.kahoot.it
Addition +
Subtraction -
Multiplication
Division
Exponent “^”
Modulus “MOD”
Floor Division “DIV”
Q13 helpsheet
number1 = 8 # store the value 8 in a variable called number1
number2 = 6 #store the value 6 in a variable called number2.
answer= number1 + number2 #add 2 numbers together and store
them in a variable called answer.
print(answer) #displays the answer.
13. Create a variable x with a value of 5. Create a variable y
with a value of 3. Create a variable z with a value 10. Multiply
three numbers together and store them in a variable called
answer. Comment on the code.
Paste your code below:
Q14 helpsheet
number1 = 8
number2 = 6
answer= number1 + number2
print(answer)
14. Alex has £20. Spending:£5 on pens. £3 on pencils. Total
amount left?
Demonstrate this example using 4 variables and arithmetic
operators. Comment on your code.
Paste your code below:
15. Ask how many apples the user wants. Ask how many
people the user will share the apples with. Find out how many
apples will remain if you share the apples equally. Hint: use
modulus %.
Paste your code below:
Q15 helpsheet
If statement
Lesson objectives…
Identify the meaning of basic relational/comparison
operators.
Identify the purpose of selection
Prepare a python program using If statements.
Demonstration:
number1 = 5
number2 = 7
answer = number1 > number2
print(answer)
KEYWORDS: Equal to, not equal to, greater than, less than
Knowledge phase
Group demonstration:
Chelsea has scored 70 goals.
Arsenal has scored 64 goals.
In total, Chelsea has scored more goals than Arsenal.
Create the above example in python to display True.
KEYWORDS: Equal to, not equal to, greater than, less than
Consolidation
• Go on
• www.kahoot.it
•Sequencing
•Selection
•Iteration
KEYWORDS: Selection, if, else, then, variables, choice, decision, condition.
Sequencing:
A set of instructions given in a
particular order.
Example:
Name= input(“Enter name”)
print(Name)
If Then
Else
KEYWORDS: If statement
17- Relational operators
Question True/False
5 == 3
2 != 5
5>6
8<2
2!=2
7==7
1>=1
7>=2
9<=2
9<=9
Q18- Move to next slide
answer=input("What is your answer? ")
if answer == "chocolate":
print("yum")
elif answer == "biscuits":
print("crunchy")
elif answer == "sweets":
print("chewy")
else:
print("I don't know what that means.")
18. Use the code on the previous slide to complete the following
table:
mancity = ____
manutd = ___
_____= _____ < ______
_____(score)
20. Create a program that asks for a person’s age. If the age is
greater than or equal to 18, display “You are old enough to
vote”, else display “You are not old enough to vote”.
Paste your code below:
Q20 helpsheet
age = __________
if ____>=18:
_____("You are old enough to vote")
____:
print(_________)
21. Create a program that asks for a person’s name. If the name
is equal to Tom, display “Welcome Tom”, else display “Hello
stranger”.
Paste your code below:
Q21 helpsheet
name = ___________
if _____ == "Tom":
print_______
____:
_____("Hello stranger")
Q22 helpsheet
print("Hello user")
singer = input("Enter your favourite singer")
if singer == "Beyonce":
print("Good singer")
elif singer =="Ed":
print("Pretty decent")
else:
print("Not too bad")
22. Create a program that Greets the user.
• Asks the user how they are feeling
• If the user enters “happy”, print “glad to hear it”
• If the user enters “sad” will tell the user a joke
• Has an error message for any other entry
Paste your code below:
Q23 helpsheet
You can only have one else and it has to be at the end.
27) Ask a user to enter a football team. If the user enters
Chelsea, display blue, else if user enters Liverpool, display red,
else display team not registered.
Paste your code below:
Q28 Helpsheet
You can only have one else and it has to be at the end.
30) Ask a user whether they want to take the red pill or the blue pill. If they
write “red” then print “red is the colour of blood”. Elif they write “blue”
then print “Are you sick?”. Else print “I don’t like that colour”
Paste your code below:
31) Ask the user to enter traffic light colour, if colour is = red,
display STOP, else if colour = yellow, display get ready, else if
colour is = green, display GO, else display an error.
Paste your code below:
Test phase:
Write a program to decide whether a year is a Leap year. The rules are:
A year is generally a Leap Year if it is divisible by 4, except that if the year is
divisible by 100, it is not a Leap year, unless it is also divisible by 400. Thus 1900
was not a Leap Year, but 2000 was a Leap year.
Paste your code below:
KEYWORDS: If statement
Revisit phase: identify the error
1. What will be the result of running this code and
entering 52?
Solution:
score = int
Score must be casted into an
integer.
Thursday, August 29, 2019
If statement
Lesson objectives…
Use IF statement to solve real life problems.
Understand the purpose of Boolean operators.
Consolidate understanding of selection.
KEYWORDS: If statement
Homework:
Use the workbook to revise for end of unit
assessment.
KEYWORDS: If statement
End of unit test
MS Form assessment:
Test link:
https://forms.office.com/Pages/ResponsePage.aspx?id=NRrmRxWbmk-
P3e1XFrwgvUKZUnHi_FpMtvQIsO11-
sxUNDAzTTRMQkdMUjFPSkJWOU82MzRGVDc5Sy4u
KEYWORDS: If statement