1 of 244

Programming technique workbook.�Python 1 section

Name:

Class:

Created by Mr Suffar

2 of 244

  • Understand how to setup Python IDLE.
  • Use the print and input functions successfully.
  • Explain the purpose of variables & constants.

Python Introduction

Lesson 1

Thursday, June 15, 2023

Lesson objectives…

Created by Mr Suffar

3 of 244

Video

Lesson 1 - Theory

Created by Mr Suffar

4 of 244

Print function

Whenever you want to display something on the screen, you must use the print command. You must ALWAYS open and close the PARANTHESIS.

Created by Mr Suffar

5 of 244

Syntax error

Syntax: The order of instructions or commands.

Syntax Error: When you break the rules of the programming language.

Examples:

  • Print(“Welcome Tom”)

  • print(“Football”

  • print(Dancing)

Created by Mr Suffar

6 of 244

Print function

1- Type the following in python:

2- Press F5 to run the program.

3- Create a program that displays your name, your country and date of birth on the screen on separate lines. Hint: Use 3 print commands.

Created by Mr Suffar

7 of 244

Variables & Constants

Variable: A location in a memory where data is stored. It can be changed while the program is running.

Constant: A location in a memory where data is stored. It cannot be changed while the program is running.

Created by Mr Suffar

8 of 244

Variables & Constants

film = "Frozen"

print (film)

film is the identifier of a variable. Used to store the value "Frozen"

Displays the value of the variable.

Value

The above program will display:

Created by Mr Suffar

9 of 244

  • Hint: You DO NOT need Quotation mark when storing numbers in a variable.

Variables & Constants

number is the identifier of a variable. Used to store the value "5"

Displays the value of the variable.

Value

Created by Mr Suffar

10 of 244

Concatenation

Concatenation: Joining things “String” together.

In python, we can use the plus sign "+" to concatenate.

What will the above program display?

BobTim

Created by Mr Suffar

11 of 244

Concatenation

Concatenation: Joining things “String” together.

In python, we can use the plus sign "+" to concatenate.

What will the above program display?

Bob Tim

Created by Mr Suffar

12 of 244

Concatenation

film = "Lion King"

print ("My favourite film is " + film)

Concatenation: Joining things “String” together.

In python, we can use the plus sign "+" to concatenate.

What will the above program display?

My favourite film is Lion King.

Created by Mr Suffar

13 of 244

Concatenation

film = "Lion King"

print ("My favourite film is " + "film")

What will this program display?

My favourite film is film

You must NOT put quotation marks around variables.

Created by Mr Suffar

14 of 244

Joining strings with a space

film = "Lion King"

print ("My favourite film is", film)

You can use a comma "," to join 2 strings together WITH A SPACE.

What will the above program display?

My favourite film is Lion King.

Created by Mr Suffar

15 of 244

Concatenation

What will this program display?

Sam Smith

Created by Mr Suffar

16 of 244

Asks for a name, wait for an answer, then displays the name on the screen.

Input function

Variable identifier called “name”

Displays the user’s answer

The question

Allows you to ask a question

Created by Mr Suffar

17 of 244

  • What will the program display if you enter Martin.
  • Your name is Martin

Input function

Variable identifier called “name”

The question

Allows you to ask a question

Created by Mr Suffar

18 of 244

Python Introduction

hobby = imput(“Enter a hobby”)

print (hobby)

Syntax errors occurs when you break the rules of the programming language.

Identify the syntax error in the code above:

  • imput should be changed to input.

Created by Mr Suffar

19 of 244

Tasks

Complete the tasks.

Created by Mr Suffar

20 of 244

1. Copy the code below, run it and test it, then explain the purpose of the program/what the program does.

school = input("Which school do you go to?")

teacher = input("Who is your favourite teacher?")

print("I go to",school,"and my favourite teacher is",teacher)

pet = input("Enter favourite pet")

print(pet*10)

Explain the purpose of the code below:

Answer:

Created by Mr Suffar

21 of 244

2. The program below must: Display Welcome user, ask user for name, and sport team, display them in a full sentence. Then ask for surname and use concatenation to display the full name. Then ask which drink they like and display it in a sentence.

Copy the code below, run it and fix the errors.

print"Welcome user"

name = imput("Enter your name"

team = input("Enter a sport team you support)

print("My name is",name"and I support",teams)

surname = input"Enter surname")

print("your full name is "name+ " " + surnme)

choice input(Do you like Tea or Coffee?")

print(choice "is a great option")

Paste the correct version below:

Created by Mr Suffar

22 of 244

3. The program below must: Store the value Rectangle in a variable called shape. It stores 5 inside the variable width and 4 inside the variable length. It then calculates the area of the rectangle by multiplying the width by length. It will then display the area in a full sentence. It will then ask the user for a shape that contains 3 sides and waits for an answer.

Copy the code below, run it and fix the errors.

shape = Rectangle

width = "5"

length = "4"

area width * length

print("The area of the",shape"is"area)

newshape= input("Triangle")

Paste the correct version below:

Created by Mr Suffar

23 of 244

4. The program below must: ask the user for school email and password then displays access granted. Then store the number 5 in a variable called number and dislay 5 is an odd number using the variable number.

Copy the code below, run it and fix the errors.

email = ("Enter your school email address")

password = input("Enter your password

primt("Access granted")

anime "One Punch Man"

rate = input(Rate the following anime: "+anime)

number = "5"

print(number"is an odd number")

Paste the correct version below:

Created by Mr Suffar

24 of 244

5. The program below must ask the user to enter a colour then store "Rose " in a variable called flower. It then print the colour followed by the flower. It then asks user to enter favourite game. It stores the number 5 inside a variable called number then it displays the game name 5 times.

colour = ______("Enter a colour")

flower = "_____"

print(colour,_____)

_____ = input("Enter your favourite game")

number = ___

print(_____*number)

Copy the code above, fill the gaps then paste your code below:

Created by Mr Suffar

25 of 244

6. The program below must ask user for a capital and display it in a full sentence. It then asks for city and displays it in a full sentence. It then stores the number 8 in a variable called squareside. It then calculates the areaofsquare using the value from squareside.

capital= ______("Enter the capital of England")

print("The capital of England is",______)

______ = input("What city do you live in?")

print(_____,"is a great city to live in")

squareside = ____

areaofsquare = squareside * _______

print("The area of a square with side length of 8 is",_______)

Copy the code above, fill the gaps then paste your code below:

Created by Mr Suffar

26 of 244

7. Display the following on 7 separate lines:

  • I like Snapchat
  • I like Instagram
  • I like Twitter
  • I love Facebook
  • Your name
  • Your age
  • Your nationality

Paste your code below:

Created by Mr Suffar

27 of 244

8. Create a variable called food and store your favourite food inside the variable (YOU DO NOT NEED TO USE THE INPUT COMMAND.) Display the value of the variable onto the screen.

Paste your code below:

Created by Mr Suffar

28 of 244

9. Create a program that ask the user for their hobby, surname, favourite colour and favourite pet. Display the above on 4 separate lines. “Remember you can’t have space in a variable name.

Paste your code below:

Created by Mr Suffar

29 of 244

10. Ask the user for their favourite film. Display the fill name in a full sentence.

Paste your code below:

Created by Mr Suffar

30 of 244

11. Create a program that ask the user for their name. Display the name 1000 times. Use * to multiply.

Example:

Paste your code below:

Created by Mr Suffar

31 of 244

12. Create a program that ask the user for their favourite food. Display “I also like”, food. Food should be replaced with the user’s answer.

Paste your code below:

hint:

Created by Mr Suffar

32 of 244

13. Ask the user for their name and favourite hobby. Display “your name is”, name, “and your favourite hobby is”, hobby. Example:

Paste your code below:

Created by Mr Suffar

33 of 244

14. Ask the user for a username. Then display “Welcome”, username.

Paste your code below:

Created by Mr Suffar

34 of 244

15. Ask the user to enter a random symbol such as #. Then display that symbol 100 times.

Paste your code below:

Created by Mr Suffar

35 of 244

16. Ask the user for their favourite colour. Then display “Your favourite colour is”, colour.

Paste your code below:

Created by Mr Suffar

36 of 244

Question 17

Answer:

Created by Mr Suffar

37 of 244

Question 18

Answer:

Created by Mr Suffar

38 of 244

Question 19

?

?

?

?

?

Created by Mr Suffar

39 of 244

Homework

Created by Mr Suffar

40 of 244

  • Revisit phase/ starter

Log on python, open your programming workbook

THEN

Create a program that asks the user if they like school or not, then display the answer.

Created by Mr Suffar

41 of 244

Data types

  • Compare different data types.
  • Create a program using variables and input command.
  • Consolidate understanding of inputs, data types and variables.

Lesson 2

Thursday, June 15, 2023

Lesson objectives…

Created by Mr Suffar

42 of 244

Data types

Lesson theory video:

https://youtu.be/ka3nBNi-j9M

Created by Mr Suffar

43 of 244

Data type: A description about the type of data a variable holds.

Why do we use data types?

The system will need to know the data type of the variable so that it can allocate the correct size of memory for the variable's data.

The computer will be unable to carry out the correct calculations on the variables unless it knows what type of data they contain.

Knowledge phase

Created by Mr Suffar

44 of 244

It is important to use the correct data type to store information because: Using the correct data type will make your programs more memory efficient. It will also make your programs more robust and predictable.

Data types

Created by Mr Suffar

45 of 244

number = -4

score = 75

age = 14

applenumber = 3

siblings = 5

Examples:

A whole number.

Integer

Created by Mr Suffar

46 of 244

Price = 1.84

weight = 7.5

Temperature = 18.5

Number= -4.00

Examples:

Any number that could be a whole number or a fraction.

Real / Float

Created by Mr Suffar

47 of 244

Grade = “C”

Gender = “M”

Symbol = “%”

Initial = “B”

Examples:

A single character.

Character

Created by Mr Suffar

48 of 244

Access= False

Repeat = True

Denied = True

Underweight = False

Examples:

Only one of two possible values - either True or False

Boolean

Created by Mr Suffar

49 of 244

Team = “Aston Villa”

Phone = “07499999222”

Name = “Brad”

Pin = “0415”

Examples:

A group of characters/text

String

Any number that starts/can start with a 0 is a STRING and is

NOT an INTEGER.

String values must have Quotation marks around them.

Created by Mr Suffar

50 of 244

Casting: Change a data type from one to another.

Example of casting in python:

num = 5

converted = str(num)

The above will change the data type of num from INTEGER to STRING and store it in a variable called converted.

num = “5.5”

convert = float(num)

The above will change the data type of num from STRING to FLOAT and store it in a variable called convert.

Casting

Created by Mr Suffar

51 of 244

Casting

Casting: Changing a data type from one to another.

Example:

age=int(input(“How old are you?”))

age = str(age)

Above line will CAST age from integer to string.

Created by Mr Suffar

52 of 244

COLD CALL

Created by Mr Suffar

53 of 244

COLD CALL

Created by Mr Suffar

54 of 244

COLD CALL

Created by Mr Suffar

55 of 244

COLD CALL

Changing a data type from one to another.

In the code above concatenation is used to join the balance to a printed message. Balance variable was casted to a string.

Created by Mr Suffar

56 of 244

  • Log on kahoot: www.kahoot.it

Easy version:

https://create.kahoot.it/share/data-types/1e607505-b2ee-4749-9dc4-5f203c50436d

Hard version:

https://create.kahoot.it/share/data-type-hard/0be31660-e005-42bb-94ba-7f4d6f9c53c3

Consolidate understanding of data type

Created by Mr Suffar

57 of 244

Python task

Copy the following code in python then click run and put any number in.

  • You can see that the answer is incorrect.
  • This is because python assumes any input is a string.

Created by Mr Suffar

58 of 244

Python task

Now copy this:

  • Now you will get the correct answer.
  • This is because we set the data type of number to an INTEGER.

Created by Mr Suffar

59 of 244

  • Complete the tasks.

Tasks

Created by Mr Suffar

60 of 244

20. Complete the following table:

Data

Data Type

Age = 15

House address = “25 James road”

Name = “Martha”

Phone number = “07777797007”

Temperature = 15.5

Price = 10.0

Adult = True

Gender = “M”

Created by Mr Suffar

61 of 244

Question 21

Answer:

Answer:

Answer:

Created by Mr Suffar

62 of 244

22. Copy the code below, run it and test it, then explain the purpose of the program/what the program does.

win = int(input("How many wins does Real Madrid have"))

draw = int(input("How many games ended in a draw for Real Madrid"))

totalpoints = (win*3) + (draw*1)

print("Total points for Real Madrid this season: ",totalpoints)

ticketcost = float(input("How much does it cost to watch Real Madrid?"))

print("Ticket price for this season is:", ticketcost)

Explain the purpose of the code below:

Answer:

Created by Mr Suffar

63 of 244

23. The program below must: Display Lakers as the winners. Asks for points scored by Lakers and Celtics then calculate the difference and displays it on the screen in a full sentence.

Copy the code below, run it and fix the errors.

prinnt("The Lakers have won over the Celtics, please enter points scored"

nba_lakers = int(input"How many points did the lakers score?"))

nba_celtics = float(input("How many points did the celtics score?")

pointdifference = nba-lakers - nba-celtics

print("The Lakers won by",pointdifferences "points")

Paste the correct version below:

Created by Mr Suffar

64 of 244

24. The program below must: Display a welcome message, ask for benchpress weight and display it in a full sentence. Then ask for number of pullups and displays it in a full sentence. Then calculate and display the strength level using the following formula: strengthlevel = (benchpress*pullups) - weight

Copy the code below, run it and fix the errors.

print("Welcome to the gym)

benchpress = float(input("How much can you bench in KG")))

print("I can bench"benchpress,"KG")

pullups = intt(input("How many pullups can you perform?"))

print("I can do",pullup,"pullups")

weight = float(inrput("How much do you weight in KG?"))

strengthlevel = (benchpress*pullups - weight

print("Your strenght level is",strengthlevel

Paste the correct version below:

Created by Mr Suffar

65 of 244

25. The program below must store 365 in a variable called daysinyear and then ask the user for their age. Then display how many days, hours, minutes and seconds they lived.

daysinyear = ____

age = ____(_____("Enter your age"))

totaldays = daysinyear*____

print("You have lived",_____, "days")

hours = totaldays*____

print("You have lived",____, "hours")

_____ = hours*60

print("You have lived",_____, "minutes")

seconds = _____*____

print("You have lived",seconds, "______")

Copy the code above, fill the gaps then paste your code below:

Created by Mr Suffar

66 of 244

26. The program below must display a message to ask the user to calculate angle 3 in a triangle then asks for angle1 and angle2 then displays the value of angle 3 in a full sentence.

_____("The sum of the angles of a triangle is 180° ,calculate angle3")

angle1 = float(_____("Enter the value of angle 1"))

angle2 = _____(input("Enter the value of angle 1"))

angle3 = ____-_____-_____

print("Angle3 is "+str(_____)+"°")

Copy the code above, fill the gaps then paste your code below:

Created by Mr Suffar

67 of 244

27. 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:

Created by Mr Suffar

68 of 244

28. Create an algorithm to calculate the area of a rectangle. Your algorithm must:

  • Asks for the user for the width.
  • Asks for the length of a rectangle.
  • Calculates and displays the area of a rectangle in a FULL sentence.

Paste your code below:

Created by Mr Suffar

69 of 244

29. Asks 2 users for their weight, calculate the average weight of the 2 users. Display the average weight in a full sentence.

Paste your code below:

Created by Mr Suffar

70 of 244

30. Asks the user to enter 3 temperatures, calculate and display the average and total of the 3 temperatures.

Paste your code below:

Created by Mr Suffar

71 of 244

31. Create an algorithm that:

  • Asks the user how many meals they want to buy.
  • Asks the user how much each meal cost (assume all of the drinks are the same price).
  • Ask the user how many drinks they want to buy.
  • Asks the user how much a drink cost (assume all of the drinks are the same price).
  • Calculate and display the total cost.

Paste your code below:

Created by Mr Suffar

72 of 244

Question 32

Answer:

Answer:

Answer:

Created by Mr Suffar

73 of 244

Question 33

Created by Mr Suffar

74 of 244

Question 34

?

?

Answer:

Created by Mr Suffar

75 of 244

Question 35

Answer:

Created by Mr Suffar

76 of 244

Question 36

?

?

?

Created by Mr Suffar

77 of 244

37. Create an algorithm that finds the perimeter rectangle.

Your program must:

  • Ask user for length
  • Ask user for width
  • Then display the perimeter of the rectangle in a full sentence.

Paste your code below:

Created by Mr Suffar

78 of 244

38. Create an algorithm that asks the user for a number, then displays helloooo, however the number of o’s in hello will be determined by the number the user enters. So if the user enters 6, then it should display helloooooo

  • .

Paste your code below:

Created by Mr Suffar

79 of 244

39. Create an algorithm that calculates the total points scored by a basketball team in a basketball match.

Create a program that:

  • Asks the user how many 2 pointers were scored.
  • Asks the user how many 3 pointers were scored.
  • Calculates the total score of the basketball team.

Paste your code below:

Created by Mr Suffar

80 of 244

40. A farmer wants to count how many legs can be counted among all his animals.

The farmer has chickens = 2 legs, cows = 4 legs, pigs = 4 legs.

Create a program that:

  • Asks the user for number of chickens
  • Ask the user for number of cows
  • Ask user for number of pigs
  • Displays the total animal legs on the farm in a full sentence.

Paste your code below:

Created by Mr Suffar

81 of 244

Created by Mr Suffar

82 of 244

Created by Mr Suffar

83 of 244

  • Demonstrate using operators to solve problems.​
  • Use operators to solve a real-world situation.
  • Understand the use of comments and round function.

Arithmetic Operators

Lesson 3

Thursday, June 15, 2023

Lesson objectives…

Created by Mr Suffar

84 of 244

Arithmetic operators: https://youtu.be/hJ0FtnWFdOE

Created by Mr Suffar

85 of 244

Arithmetic Operators

Command

Name

Example

Output

*

Multiplication

6*5

30

/

Division

6/3

2

MOD (% in Python)

Modulus / modulo

10 MOD 3

1

^ (** in Python)

Exponent

3^2

9

DIV ( // in Python)

Integer Division

10 DIV 3

3

Created by Mr Suffar

86 of 244

COLD CALL

Created by Mr Suffar

87 of 244

COLD CALL

3

1

Created by Mr Suffar

88 of 244

COLD CALL

Created by Mr Suffar

89 of 244

Consolidation

Created by Mr Suffar

90 of 244

Commenting

  • Commenting is used to allow programmers to understand the purpose of the code.
  • In python, we use # to comment on code. Examples below:

Created by Mr Suffar

91 of 244

ROUND function

  • The round function allows you to round a number to the nearest whole number.
  • Displays: 6
  • Displays: 5
  • Displays: 5.77 - this Round a number to two decimals

Created by Mr Suffar

92 of 244

  • Complete the tasks

Apply your knowledge to tasks

Created by Mr Suffar

93 of 244

41. Complete the following table:

Question

Answer

9 * 10 =

20/4 =

print(round(5.7))

print(round(6.87895 , 2))

5 ** 2 =

5 % 2 =

5 // 2 =

Created by Mr Suffar

94 of 244

42. Copy the code below, run it and test it, then explain the purpose of the program/what the program does.

Explain the purpose of the code below:

icecream = int(input("How many icecreams do you want?"))

milkshake = int(input("How many milkshakes do you want?"))

iceprice = float(input("Enter the price of each icecream"))

milkprice = float(input("Enter the price of each milkshake"))

total = (icecream*iceprice) + (milkshake*milkprice)

print("The total amount that you have to pay is:",round(total))

Answer:

Created by Mr Suffar

95 of 244

43. Copy the code below, run it and test it, then explain the purpose of the program/what the program does.

Explain the purpose of the code below:

footballteam = int(input("How many players does your team currently have?"))

playersneeded = 11 % footballteam

print("You need:",playersneeded,"players before the match can start")

Answer:

Created by Mr Suffar

96 of 244

44. Copy the code below, run it and test it, then explain the purpose of the program/what the program does.

Explain the purpose of the code below:

students = int(input("How many students are in the class?"))

kpopfans = int(input("How many students listen to KPOP"))

percentage = kpopfans/students * 100

twodecimal = round(percentage,2)

print("Percentage of students who listen to KPOP is:",twodecimal,"%")

Answer:

Created by Mr Suffar

97 of 244

45. The program below must: Ask for number of people at a dinner table. Asks for the total bill. Asks for the percentage TIP to be added on top of the bill that the group want to pay. Calculates and display the total amount to be paid after the TIP is added. Calculates and displays how much each person will pay rounded to 2 decimal places.

Copy the code below, run it and fix the errors.

people = str(input("How many people are at the dinner table"))

bill = float(inrput("Enter the total bill for the food")

percentage = int(input("What percentage of the bill do you want to pay as a tip?"))

total = bills + ((bill/100) * percentage

payeach = total :) people

print("Total amount to be paid with TIP is:",nothing)

print("Each person will pay",round(payeach,8))

Paste the correct version below:

Created by Mr Suffar

98 of 244

46. A school teacher is organising a trip and wants to calculate the total cost of a trip and the total amount need to be paid by each student.

The program below must: Ask the user for cost of bus, hotel and activities. Ask for number of students. Calculate and displays the overall total cost of the trip. Calculates and dispays the amount each student needs to pay rounded to the nearest whole number.

Copy the code below, run it and fix the errors.

bus = float(input("How much does hiring the full bus cost")))

hotel = bool(input(("Enter total cost of all rooms needed"))

activities = float(inputt("Enter total cost of all activities"))

students = int(input("Enter number of students))

totalcost = bus+hotel+activitie

payeach = totalcost * students

print("Total overall cost of the trip,"totalcost)

print("Total cost to be paid by each student:",rounds(payeach))

Paste the correct version below:

Created by Mr Suffar

99 of 244

47. A basketball coach wants to share energy drinks evenly between his players.

Create a program that:

  • Asks the user for the number of energy drinks.
  • Asks the user for the number of players the drinks need to be shared with.
  • Calculate and display how many energy drink each player will receive.

drinks = ____(____("How many energy drinks needed?"))

players = ____(____("How many players are in the team?"))

drinkeach = drinks // ____

drinksremain = ____ % players

print("Each player will receive:",____,"drink")

print("Drinks remaining:",____)

Copy the code above, fill the gaps then paste your code below:

Created by Mr Suffar

100 of 244

48.

  • Create a variable x and assign the value 5 to it.
  • Create a variable y and assign the value 3 to it.
  • Create a variable z and assign the value 10 to it.
  • Multiply three numbers together and store them in a variable called answer.
  • Display the value of answer
  • Comment on the code using #.

Paste your code below:

Created by Mr Suffar

101 of 244

49. Create a program that:

  • Ask the user for 3 numbers.
  • Create a variable called answer and store the value of the first number multiplied by the second number.
  • Create another variable called “finalanswer” and store the value of the “answer” variable divided by the 3rd number.
  • Display the value of finalanswer.

Paste your code below:

Created by Mr Suffar

102 of 244

50. A pay to win Fifa player is buying Fifa coins to buy players. Players receive 105 Fifa coins per 1$.

Create a program that:

  • Asks the user how much they want to spend on fifa coins in $. Hint: use float.
  • Display the number of coins the player will receive rounded to the nearest whole number.

Paste your code below:

Created by Mr Suffar

103 of 244

51. Create a program that:

  • Ask how many apples the user wants.
  • Ask how many people the user will share the apples with.
  • Finds out how many apples will remain if you share the apples equally.
  • Hint: use modulo % (finding the remainder).
  • Display the how many apples remain in a full sentence.

Paste your code below:

Created by Mr Suffar

104 of 244

52. Create a program that:

  • Asks the user for number of drinks needed.
  • Asks user for price of each drink assuming they are all the same price.
  • Displays the total price needs to be paid rounded to 2 decimal points.

Paste your code below:

Created by Mr Suffar

105 of 244

53. Create a program that:

  • Asks for the home team name.
  • Asks for the opponent team name.
  • Asks for the number of goals scored by the home team.
  • Asks for the number of goals scored by the opposition team.
  • Calculates the goal difference for the home team. (Could be a negative difference)
  • Display the goal difference in a full sentence.

Paste your code below:

Created by Mr Suffar

106 of 244

54. A group of students are going to the shop to buy sweets. The students want to share the sweets and payment evenly. The students want to donate any remaining sweets. Create a program that:

  • Asks how many sweets needed.
  • Asks for the number of students.
  • Asks how much the total sweets cost.
  • Calculates and displays how much each student need to pay.
  • Calculates and displays how many sweets each student receives.
  • Calculates and displays how many sweets remain (use Modulus “%” for this)

Paste your code below:

Created by Mr Suffar

107 of 244

55. Create a program that calculates how many hours, minutes and seconds are in a week. Display each answer in a full sentence.

Paste your code below:

Created by Mr Suffar

108 of 244

56. A shop owner pays 20% tax on each item they sell. Create an algorithm that:

  • Asks the customer how many sweets they want to buy.
  • Asks the shop owner how much each sweet costs (assume they all cost the same price).
  • Calculates the total amount and adds 20% on top and stores it in a variable called after “finaltotal”.
  • Display the total amount after tax in a full sentence.

Paste your code below:

Created by Mr Suffar

109 of 244

57. A user wants to measure the length of his car. Create an algorithm that:

  • Asks the user to enter the length in CM.
  • Convert the length to inches. (0.393701 INCH in 1 CM)
  • Display the length in inches.

Paste your code below:

Created by Mr Suffar

110 of 244

58. The following formula is used to convert Celsius to Fahrenheit: Y°F =(X°C × 9/5) + 32

  • X represents the value in Celsius and Y represent the value in Fahrenheit.
  • Use the formula above to create an algorithm that converts Celsius to Fahrenheit.

Your algorithm must:

  • Ask the user for the temperature in Celsius.
  • Converts the temperature into Fahrenheit.
  • Displays the answer in a full sentence.

Paste your code below:

Created by Mr Suffar

111 of 244

59. A shop wants to create an online payment system using gift cards only.

Create an algorithm that:

  • Asks how much the customer’s items cost in total.
  • Asks the customer if they are paying using £20 gift card, £40 gift card, £50 gift card or £100 gift card.
  • Displays how much was deducted from the gift card
  • Display how much money remains in the gift card.

Paste your code below:

Created by Mr Suffar

112 of 244

60. The formula to calculate the file size of a sound file is:

File size (bits) = Sampling rate (Hz) × Resolution (bits) × Length of sample (seconds)

Create an algorithm that:

  • Asks the user to input the sample rate.
  • Asks the user to input the resolution.
  • Asks the user to input the length of the sample in minutes.
  • Calculates and stores the file size in a variable called “size”.
  • Displays the file size (in bits) in a full sentence.

Paste your code below:

Created by Mr Suffar

113 of 244

61. Tom wants to hire a car. He wants to know how much it will cost him to drive to a different city and back.

The hiring company charges the following:

  • A booking fee of £5
  • First mile costs = £2
  • Rest of the miles cost: 0.25 per mile.

Tom also needs to fill the car with Diesel, the car uses approximately £0.5 in diesel per mile.

Create an algorithm that:

  • Asks the user how many miles are they going to travel.
  • Calculates and displays the total cost of the journey.

Paste your code below:

Created by Mr Suffar

114 of 244

62. Create a program that calculates the area of a circle.

Area of circle formula is PI*R^2 so: PI * RADIUS * RADIUS

Your algorithm must:

  • Ask the user for the radius
  • Create a variable called pi and set it to 3.14
  • Calculates and displays the area of the circle in a full sentence.

Paste your code below:

Created by Mr Suffar

115 of 244

63. Create a program that calculates the area of a triangle.

Area of triangle formula: (base* height) / 2

Your algorithm must:

  • Ask the user for the base
  • Ask the user for the height
  • Create a variable called area and stores the area of the triangle.
  • Displays the area of the triangle in a full sentence.

Paste your code below:

Created by Mr Suffar

116 of 244

64. In a tea shop, for each 6 tea cups bought by a customer, the customer gets 1 free. So if they pay for 12 cups, they get 14 in total.

Create a program that:

  • Asks for numbers of tea cups bought
  • Calculates and displays the number of free cups received.
  • Calculates and displays the total number of cups received in a full sentence.

Paste your code below:

Created by Mr Suffar

117 of 244

65. This is a task for a game called “Among us the imposter game”.

Create a program that calculates the chances of being an imposter in a game. The formula to calculate the chances of being an imposter is: 100 x (i / p) where i is the number of imposters and p is the total number of all players.

Create a program that:

  • Asks the user for number of imposters.
  • Ask for total number of players.
  • Calculate and display the percentage chance of being an imposter using the above formula and round it to the nearest whole number.

Paste your code below:

Created by Mr Suffar

118 of 244

Task 66

Paste your python code below:

Created by Mr Suffar

119 of 244

Homework

Created by Mr Suffar

120 of 244

1. State the values of a, b, c, d and e after the following operations are carried out:

(a) a = 26 MOD 5 =

(b) b = 50 DIV 7 =

(c) c = 10 ^ 3 =

(d) d = 10 MOD 5 =

(e) e = “4” + “56” =

Revisit phase / Starter

?

?

?

?

?

Created by Mr Suffar

121 of 244

  • Identify the meaning of basic comparison operators.
  • Identify the purpose of selection
  • Prepare a python program using If statements.

If statement

Lesson 4

Thursday, June 15, 2023

Lesson objectives…

Created by Mr Suffar

122 of 244

Lesson theory

Created by Mr Suffar

123 of 244

Comparison Operators

Operator

Meaning

Example

True/False

>

Greater than

44 > 5

<

Less than

33<20

==

Equal to

10==20

!=

Not equal to

5 != 2

>=

Greater than OR equal to

20>=20

<=

Less than OR equal to

5<=10

True

False

False

True

True

True

Created by Mr Suffar

124 of 244

Consolidation phase- Your turn

Operator

Meaning

Example

True/False

>

Greater than

2 > 5

<

Less than

23<20

==

Equal to

16==16

!=

Not equal to

7 != 7

>=

Greater than OR equal to

11>=20

<=

Less than OR equal to

30<=30

False

False

True

False

False

True

Created by Mr Suffar

125 of 244

Application phase – Apply what you have learnt!

Created by Mr Suffar

126 of 244

If statement

Then

If

Else

SELECTION: A programming construct that decides which statements are to be executed depending upon the result of a question/condition.

Created by Mr Suffar

127 of 244

Structure of an if statement

name = input("Enter a name")

if name == "Rose":

print("Hi Rose")

Variable

Asks the user to input a name

After writing if, you need a condition.

A condition must end with a COLON :

This space (TAB) represents Indentation which signifies the start and end of a block of code.

Created by Mr Suffar

128 of 244

Structure of an if statement

name = input("Enter a name")

if name == "Rose":

print("Hi Rose")

else:

print("Who are you")

Means OTHERWISE. It will display Who are you If anything other than Rose is entered.

Must end with a colon

Must be indented.

Created by Mr Suffar

129 of 244

Structure of an if statement

name = input("Enter a name")

if name == "Rose":

print("Hi Rose")

elif name == "Sarah":

print("Hi Sarah")

else:

print("Who are you")

Elif stands for ELSE IF. You can have as many elif as you want in a single if statement, however you can only have 1 if and 1 else.

Remember to always put

" Quotation marks" around strings.

Created by Mr Suffar

130 of 244

Structure of an if statement

password = input("enter a password")

if password == "Over123":

print("Access Granted")

elif password == "Overwatch": print("close")

else:

print("Access Denied")

What will this program display if the user enters Overwatch as the password?

Close

Created by Mr Suffar

131 of 244

Structure of an if statement

password = input("enter a password")

if password == "Over123":

print("Access Granted")

elif password == "Overwatch": print("close")

else:

print("Access Denied")

What will this program display if the user enters Over123 as the password?

Access Granted

Created by Mr Suffar

132 of 244

Structure of an if statement

password = input("enter a password")

if password == "Over123":

print("Access Granted")

elif password == "Overwatch": print("close")

else:

print("Access Denied")

What will this program display if the user enters Potatos123 as the password?

Access Denied

Created by Mr Suffar

133 of 244

Structure of an if statement

powerlevel= int(input("enter power level"))

if powerlevel > 9000:

print("Over 9000")

elif powerlevel < 9000:

print("Less than 9000")

else:

print("It is 9000")

What will this program display if the user enters 9500 as the power level?

Over 9000

Note: DO NOT PUT "QUOTATION MARKS" AROUND NUMBERS.

Created by Mr Suffar

134 of 244

Nested if statement

socialmedia = input("Do you use social media?")

if socialmedia == "yes":

platform = input("Which platform do you use?")

if platform == "Facebook":

print("You are too old")

else:

print("Good choice")

else:

print("Good choice, social media is addictive")

Nested if statement

is an if statement inside another if statement.

Created by Mr Suffar

135 of 244

  • Complete the tasks.

Application phase – Apply your knowledge

Created by Mr Suffar

136 of 244

Task 67 – State whether the following statements are True or False

Question

True/False

5 == 3

2 != 5

5 > 6

8<2

2!=2

7==7

1>=1

7>=2

9<=2

9<=9

Created by Mr Suffar

137 of 244

68. Copy the code below, run it and test it, then explain the purpose of the program/what the program does.

Explain the purpose of the code below:

youtubeceleb = input("Enter the name of a youtube celebrity")

if youtubeceleb == "mrbeast":

print("Correct")

else:

print("Try again")

Answer:

Created by Mr Suffar

138 of 244

69. Copy the code below, run it and test it, then explain the purpose of the program/what the program does.

Explain the purpose of the code below:

mark = int(input("Enter mark"))

if mark >=70:

print("Distinction")

elif mark >= 50:

print("Merit")

else:

print("Pass")

Answer:

Created by Mr Suffar

139 of 244

70. Copy the code below, run it and test it, then explain the purpose of the program/what the program does.

Explain the purpose of the code below:

binary = input("Would you like to enter a binary number?")

if binary == "yes":

binarynum = input("Enter a binary number")

else:

denary = input("Would you rather enter a denary number then?")

if denary == "yes":

denarynum = int(input("Enter a denary number"))

else:

print("You are boring")

Answer:

Created by Mr Suffar

140 of 244

71. Copy the code below, run it and test it, then explain the purpose of the program/what the program does.

Explain the purpose of the code below:

# Example purchase amount

purchase_amount = 150

# If statement to determine discount

if purchase_amount >= 1000:

discount = 0.2 # 20% discount

elif purchase_amount >= 500:

discount = 0.1 # 10% discount

elif purchase_amount >= 200:

discount = 0.05 # 5% discount

else:

discount = 0 # No discount

discount_amount = purchase_amount * discount

final_amount = purchase_amount - discount_amount

print("Purchase amount:", purchase_amount)

print("Discount:", discount_amount)

print("Final amount:", final_amount)

Answer:

Created by Mr Suffar

141 of 244

72. The program below must: Ask for a country name, display Pyramids if “Egypt” is entered, displays COLD! If “Iceland” is entered, displays Taj Mahal if “India” is entered. Display Accepted for any other choice.

Copy the code below, run it and fix the errors.

country = input("Enter a country name"

if country = "Egypt":

print("Pyramids")

elseif country == Iceland:

print("COLD!")

elif countrys == "India"

print(Taj Mahal")

else

prints("Accepted")

Paste the correct version below:

Created by Mr Suffar

142 of 244

73. The program below must: Ask the user for a score, then determines the grade.

Copy the code below, run it and fix the errors.

score = int(input("Enter the score"))

if score >= 90

grade = "A"

elif score => 80:

grade = "B"

elif score >= "70":

grade = "C"

elif score >= 60

grade = D

else:

grade = "F"

print("The grade is" grade)

Paste the correct version below:

Created by Mr Suffar

143 of 244

74. The program below must: ask for price and then set the category to Low/Medium/High/Premium depending on the price. It then displays the category. Low is below 10, medium is between 10 and 30, high is between 30 and 49. Premium is 50 or above.

Copy the code below, run it and fix the errors.

price = floa(input("Enter price"))

# Nested if statement

if price < 10

category = Low"

elseif price < 50:

if price < 30:

category "Medium"

else:

category = "High"

else:

category = "Premium

print("Category:" category)

Paste the correct version below:

Created by Mr Suffar

144 of 244

75. The program below must: Calculate if the year is a leap year. A leap year is a year that is (divisible by 4 but not divisible by 100) OR (Divisible by 4, 100 and 400).

Copy the code below, run it and fix the errors.

year = int(input("Enter a year")

# If statement to check leap year

if year % 4 == 0

if year % 100 == 0:

if year MOD 400 == 0:

print(year, "is a leap year")

else

print(year, "is not a leap year")

else:

print(year, "is a leap year")

else:

print(year "is not a leap year")

Paste the correct version below:

Created by Mr Suffar

145 of 244

76. Create a program that:

  • Asks the user for a 3 digit pin number. If the number is “007” then display “It’s BOND”. Otherwise, display “Boring”.

digit = _____("Enter a 3 digit pin number")

if digit == "____":

____("It's BOND")

____:

____("Boring")

Copy the code above, fill the gaps then paste your code below:

Created by Mr Suffar

146 of 244

77. Create a program that:

  • Ask the user for 2 numbers, then display “Divisible” if the first number divide by the second number and gives you a whole number. If not, display Not divisible.

num1 = ____(____("Enter first number"))

num2 = ____(____("Enter second number"))

if num1 / ____ == num1 // num2:

____("Divisible")

else:

____("Not divisible")

Copy the code above, fill the gaps then paste your code below:

Created by Mr Suffar

147 of 244

78. Create a program that:

  • You want to see how much using a mobile phone will cost. There are charges for sending pictures (£0.35), for texts (£0.10) and for data (£2.50 for 500MB).�Write a program that asks the user for how many pictures, texts and data they would use each month. It should then calculate a total and display bill for the month. Round your answer to 2 decimal points.�If the total comes to more than £10 they would get a printed message to say “You will be better on a contract. Get the programme to give them this advice.

pictures = ___(___("How many pictures did you send?"))

texts = ___(___("How many texts did you send?"))

data = ___(___("How many MB of data have you used?"))

bill = (___*0.35) + (___*0.10) + ((data / 500) * 2.50)

print("Bill for the month:",round(___,2))

if bill >___:

___("You will be better on a contrat")

Copy the code above, fill the gaps then paste your code below:

Created by Mr Suffar

148 of 244

79. Create a program that: Asks for time of day in the following format: hours.minutes example: 18.30. It then displays whether its morning, afternoon or evening.

hour = ____(____("Enter time of day, E.G: 17.30"))

# Nested if statement

if ____ < 12:

time_of_day = "____"

else:

if hour < ____:

time_of_day = "Afternoon"

____:

time_of_day = "Evening"

print("Time of Day:", ____)

Copy the code above, fill the gaps then paste your code below:

Created by Mr Suffar

149 of 244

80. Create a program that:

  • Asks for the user’s age.
  • If the age is 18 or above, display “You are old enough to vote”
  • Otherwise display “You are not old enough to vote”.

Paste your code below:

Created by Mr Suffar

150 of 244

81. Create a program that:

  • Asks for the user’s name.
  • If the user enters Nina as the name, display “Welcome Nina”,
  • Otherwise display “Hello stranger”.

Paste your code below:

Created by Mr Suffar

151 of 244

82. Create a program that:

  • Asks the user for their test score.
  • If the score is 40 or above, display “You Passed!”.
  • Otherwise display “You did not pass. Try again”.

Paste your code below:

Created by Mr Suffar

152 of 244

83. Create a program that:

  • Asks the user for a password.
  • If the user enters Python as the password, display “Access Granted”,
  • Otherwise display “Access Denied”.

Paste your code below:

Created by Mr Suffar

153 of 244

84. Create a program that:

  • Greets the user by displaying “Welcome user” on the screen.
  • Asks the user for favourite singer.
  • If the user enters “Beyonce”, Display “Good singer”
  • If the user enters “Ed”, display “Pretty decent”
  • Displays “Not too bad” for any other entry

Paste your code below:

Created by Mr Suffar

154 of 244

85. Create a program that:

  • Ask user to enter a grade.
  • If the grade is 90 or above, display “Grade 9 / A**”
  • if grade 80 or above, display “Grade 8 / A*”
  • if grade 70 or above, display “Grade 7 / A”
  • Otherwise, display “Pass”.

Paste your code below:

Created by Mr Suffar

155 of 244

86. Create a program that:

  • Ask the user the following: “Is there a lockdown?”
  • If the user types “No” as the answer, display “Have a good day”
  • Otherwise ask them if they are at home. If they they type “yes” as the answer, display “Well done”, otherwise display “Go home”.

Hint: Use nested if statement (an if statement inside another if statement)

Paste your code below:

Created by Mr Suffar

156 of 244

87. Create a program that:

  • Ask the user to input 2 numbers.
  • Ask the user if they want to multiply the numbers together.
  • If the user enters “Yes”, multiply the 2 numbers together and display the answer.
  • Otherwise display “Ok boss”.

Paste your code below:

Created by Mr Suffar

157 of 244

88) Create a program that:

  • Asks the user to enter a number.
  • If the number is larger than 100, display “too large”.
  • Otherwise display “too small”.

Paste your code below:

Created by Mr Suffar

158 of 244

89) Create a program that:

  • Asks the user to enter a football team name.
  • If the user enters Chelsea, display blue.
  • If user enters Liverpool, display red.
  • Otherwise display team not registered.

Paste your code below:

Created by Mr Suffar

159 of 244

90) Create a program that:

  • Asks the user to enter 2 numbers.
  • If the first number is bigger than 10, add the two numbers.
  • Otherwise multiply the two numbers.
  • Display the result.

Paste your code below:

Created by Mr Suffar

160 of 244

91) A manager of an amusement park wants to create an algorithm for a new discount. A ticket costs £20. There is a 50% discount for people who hold season tickets and 25% for people without a season ticket.

Your algorithm must:

  • Ask the user if they have a season ticket or not.
  • Display the final price after the discount.

Paste your code below:

Created by Mr Suffar

161 of 244

92) Create a program that:

  • Ask the user to enter traffic light colour.
  • If colour is = red, display STOP.
  • If colour = yellow display get ready.
  • If colour is = green, display GO.
  • Otherwise display an “Error”.

Paste your code below:

Created by Mr Suffar

162 of 244

93) Create a program that:

  • Asks the user to enter two numbers.
  • Ask them if they want the numbers added or multiplied.
  • If the user enters add, add the 2 numbers together then display it on the screen.
  • If the user enters multiply, multiply the 2 numbers together then display it on the screen.
  • Otherwise display “Wrong answer”.

Paste your code below:

Created by Mr Suffar

163 of 244

94) Create a program that:

  • Asks the user to enter one of the two colours that makes green.
  • If the user enters yellow, display “Correct! The other colour is blue”.
  • If the user enters blue, display “Correct! The other colour is yellow”.
  • Otherwise display “Incorrect colour”.

Paste your code below:

Created by Mr Suffar

164 of 244

95) Create a program that:

  • Asks the user to enter the number of sides a shape has.
  • If the user enters 3, display “Triangle”.
  • If user enters 4, display “Square”.
  • If user enters 5, display “Pentagon”.
  • Otherwise display “Shape not registered”.

Paste your code below:

Created by Mr Suffar

165 of 244

96) Create a program that:

  • Asks the user to enter a number.
  • Ask the user if they want the number to be doubled or tripled.
  • If the user enters doubled, multiply the number by 2 and display the answer as a full sentence.
  • If the user enters tripled, multiply the number by 3 and display the answer as a full sentence.
  • Otherwise display “Wrong answer”.

Paste your code below:

Created by Mr Suffar

166 of 244

97) A circle can fit inside a square if the diameter of the circle does not exceed the length of a square side.

  • Create a program that:
  • Asks the user to enter the length of the square side.
  • Enter the radius of a circle.
  • Calculate and display the diameter of the circle.
  • Calculate the area of the square.
  • Calculates the area of the circle.
  • Displays whether the circle can or can not fit inside the square.

Paste your code below:

Created by Mr Suffar

167 of 244

Task 98

Paste your python code below:

Created by Mr Suffar

168 of 244

Task 99

Answer:

Created by Mr Suffar

169 of 244

Homework

Created by Mr Suffar

170 of 244

age = int(input("Enter your age"))

if age>=18:

print("You are old enough to vote")

elif age==17:

print("You can vote in 1 year")

else:

print("You are still too young")

Revisit phase - Starter

What will the following program display? If the user enters 17?

What will the following program display? If the user enters 19?

What will the following program display? If the user enters 14?

Created by Mr Suffar

171 of 244

  • Use IF statement to solve real life problems.
  • Understand the purpose of Boolean operators.
  • Use Boolean operators to create algorithms.

If statement part 2

Lesson 5

Thursday, June 15, 2023

Lesson objectives…

Created by Mr Suffar

172 of 244

Lesson theory video

Created by Mr Suffar

173 of 244

Knowledge phase

Boolean operators can be used to make selection statements more efficient and versatile. We use AND, OR & NOT.

It’s important to use brackets in long Boolean expressions.

Order: Brackets, NOT, AND then OR.

Created by Mr Suffar

174 of 244

AND OPERATOR

The AND operator will output True if both sides are true, otherwise it will be False.

For example:

Boolean expression

True/False

Reason

5 > 2 AND 8 < 12

True

Both sides are True.

11 > 5 AND 7 == 3

False

Right side is False, so overall statement will be False

Created by Mr Suffar

175 of 244

OR OPERATOR

The OR operator will output True if either or both sides are true, otherwise it will be False.

For example:

Boolean expression

True/False

Reason

10 == 10 OR 7 < 12

True

Both sides are True.

11 > 5 OR 5 == 3

True

Left side is True, so overall statement will be True

10 == 5 OR 11> 20

False

Both sides are False

Created by Mr Suffar

176 of 244

NOT OPERATOR

The NOT operator reverses the statement, if it’s True it become False, if it’s False it becomes True.

For example:

Boolean expression

True/False

Reason

NOT (20== 20)

False

20== 20 is True, so reverse of true is False

NOT (10 < 5)

True

10 < 5 is False, so reverse of False is True

NOT (25> 20)

False

25 > 20 is True, so reverse of true is False

Created by Mr Suffar

177 of 244

COLD CALL

Boolean expression

True/False

11 > 5 AND 7 == 3

NOT(13 == 2)

11 <= 2 OR 8 != 5

NOT(12 > 2 AND 5 < 1)

False

True

True

True

Created by Mr Suffar

178 of 244

If statement

n = int(input("Enter a number"))

if n == 2 or n == 3:

print("Correct")

else:

print("Incorrect")

What will this program display if the user enters 10 as the number?

Incorrect

What will this program display if the user enters 2 as the number?

Correct

Created by Mr Suffar

179 of 244

Consolidation

Created by Mr Suffar

180 of 244

name = input(“What is your name?”)

if name == "James" or name == "Don":

print("I know you!")

else:

print("Who are you?")

Example:

What will this program display if the user enters James as the name?

I know you!

What will this program display if the user enters Bradley as the name?

Who are you?

Created by Mr Suffar

181 of 244

We can use the AND operator to find if a number is between 2 specific numbers.

num = int(input("Enter a number"))

if num >=1 and num<=10:

print("Correct")

else:

print("Incorrect")

Range Check

What will this program display if the user enters the number 5?

Correct

Created by Mr Suffar

182 of 244

We can use the OR operator to find if a number DOES NOT fall between 2 specific numbers.

num = int(input("Enter a number"))

if num <1 or num>10:

print("Incorrect")

else:

print("Correct")

Range Check

What will this program display if the user enters the number 22?

Incorrect

Created by Mr Suffar

183 of 244

Modulus

We can use Modulus to find if a number is odd or even.

Example:

10 % 2 = 0

6 % 2 = 0

100 % 2 = 0

8 % 2 = 0

98 % 2 = 0

As you can see, you can use modulo 2 to find if the number is even.

If the remainder is 0, then it’s even, if the remainder is 1, then its odd.

Created by Mr Suffar

184 of 244

  • Complete the tasks

Application phase

Created by Mr Suffar

185 of 244

100. Copy the code below, run it and test it, then explain the purpose of the program/what the program does.

Explain the purpose of the code below:

side1= int(input("Enter the length 1"))

side2= int(input("Enter the length 2"))

side3= int(input("Enter the length 3"))

# If statement to determine the type of triangle

if side1 == side2 and side2== side3:

triangle_type = "Equilateral"

elif side1 == side2 or side1 == side3 or side2 == side3:

triangle_type = "Isosceles"

else:

triangle_type = "Scalene"

print("The triangle is", triangle_type)

Answer:

Created by Mr Suffar

186 of 244

101. Copy the code below, run it and test it, then explain the purpose of the program/what the program does.

Explain the purpose of the code below:

purchase_amount = float(input("Enter purchase amount"))

membership_level = input("Enter membership level")

# Nested if statement with logical operators

if purchase_amount >= 100 and membership_level == "Gold":

discount = 0.2

elif purchase_amount >= 50 or membership_level == "Silver":

discount = 0.1

else:

discount = 0

final_amount = purchase_amount - (purchase_amount * discount)

print("Purchase Amount:", purchase_amount)

print("Membership Level:", membership_level)

print("Discount Percentage:", discount * 100, "%")

Answer:

Created by Mr Suffar

187 of 244

102. Copy the code below, run it and test it, then explain the purpose of the program/what the program does.

Explain the purpose of the code below:

age = int(input("Enter your age"))

is_student = input("Are you a student? True or False")

if age < 5 or age >= 60:

print("Free ticket")

else:

if is_student== True:

print("Student ticket: $10")

else:

if age >= 18:

print("Adult ticket: $15")

else:

print("Child ticket: $8")

Answer:

Created by Mr Suffar

188 of 244

103. The program below must: Ask for value of angle, displays Acute if the angle is less than 90. Display Right if the angle is 90. Display Obtuse if the angle is between 91 and 179. Otherwise display Straight.

Copy the code below, run it and fix the errors.

angle = int(input("Enter angle")

# If statement to determine angle type

if angle < 90

angle_type = "Acute"

elif angle = 90:

angle_type = "Right"

elif angle > 90 or angle < 180:

angle_type = "Obtuse"

else

angle_type = "Straight"

print("The angle is" angle_type)

Paste the correct version below:

Created by Mr Suffar

189 of 244

104. The program below must: Ask the user for age, display whether the user is a child, adult or senior depending on their age. If the user is less than 18 they are a child, if the user is between 18 and 64, they are an Adult. Otherwise they are Senior.

Copy the code below, run it and fix the errors.

age = str(input("Enter your age"))

# If statement to determine age category

if age > 18:

category = "Child

elif age >= 18 or age < 65:

category = "Adult"

else

category = "Senior"

print("The age category is" category)

Paste the correct version below:

Created by Mr Suffar

190 of 244

105. The program below must: The program must take 2 inputs, grade and income, representing the student's grade and annual income, respectively. The if statement checks the grade and income against specific criteria to determine the scholarship eligibility. If the grade is 90 or above and the income is less than $60,000, the student is eligible for a full scholarship. If the grade is 80 or above and the income is less than $80,000, the student is eligible for a partial scholarship. If the criteria for either scholarship is not met, the student is not eligible for a scholarship. Finally, it prints the scholarship eligibility status.

Copy the code below, run it and fix the errors.

grade = int(inrput("Enter grade"))

income = int(input("Enter income")

# If statement to determine scholarship eligibility

if grade >= 90 and income < 60000

eligibility = "Eligible for Full Scholarship"

elif grade >= 80 or income < 80000:

eligibility = "Eligible for Partial Scholarship"

else

eligibility = "Not Eligible for Scholarship"

print("Scholarship eligibility:", eligibilityyy)

Paste the corrected version below

Created by Mr Suffar

191 of 244

106. Create a program that:

  • Ask user for age, display “You are eligible for this program” if the user is between 18 and 30 inclusive. Otherwise display “You are not eligible for this program.”

age = ____(____("Enter your age: "))

# Check if the age is between 18 and 30 (inclusive)

if age >= 18 ____ age <= 30:

____("You are eligible for this program.")

____:

____("You are not eligible for this program.")

Copy the code above, fill the gaps then paste your code below:

Created by Mr Suffar

192 of 244

107. Create a program that:

  • Asks the user for a number, display “The number is even and positive” if the number is even and also positive at the same time. Otherwise display “The number is not even and positive.”

num = __(____("Enter a number: "))

# Check if the number is even and positive

if num % 2 == __ and num > __:

_____("The number is even and positive.")

_____:

_____("The number is not even and positive.")

Copy the code above, fill the gaps then paste your code below:

Created by Mr Suffar

193 of 244

108. Create a program that:

  • Gives users a message depending upon how happy they say they are. �Ask the user how happy they feel on a scale between 1 and 10. If the reply is 3 or less it gives one message. Between 4 and 7 (including these numbers) they get another message.�8 and above they get a different message.�Try to make the messages ones to make them happy all day long!

rating = int(input("On a scale of 1 to 10, how happy do you feel? "))

# Check happiness rating and display corresponding message

if rating <= ___:

print("I'm sorry to hear that you're feeling low.")

___ happiness_rating >= 4 ___ happiness_rating <= 7:

print("It sounds like you're doing okay. Stay positive.")

___:

___("That's wonderful to hear!")

Copy the code above, fill the gaps then paste your code below:

Created by Mr Suffar

194 of 244

109) Create a program that:

  • Asks the user to enter a username and password.
  • If they get the username AND password are correct, display a “logged in” Otherwise, display “Incorrect details”.
  • Assume correct username= “RushB” and correct password = “CSGO”

Paste your code below:

Created by Mr Suffar

195 of 244

110) Create a program that:

  • Ask the user if they play games on pc.
  • Ask them if they play on console.
  • if pc = yes and console = yes, display Game master
  • if pc = yes and console = no, display pc master
  • if pc = no and console = yes, display console master
  • Display “Error” for any other inputs.

Paste your code below:

Created by Mr Suffar

196 of 244

111) Create a program that:

  • Asks for the user’s age.
  • If the age is between 13 and 19, display “You are a teenager”.
  • If the age is 11 or 12, display “You are a tween.”
  • Otherwise display “Invalid age”.

Paste your code below:

Created by Mr Suffar

197 of 244

112) Create a program that:

  • Asks the user for current temperature.
  • Asks the user if it’s raining outside.
  • If temperature is less than 13 and it’s raining, display “Wear a coat and bring an umbrella”.
  • If temperature is less than 13 degrees and it’s not raining, display “Wear a coat”.
  • If temperature is 13 or above, and it’s raining, display bring an umbrella.
  • Otherwise display “you don’t need a coat or an umbrella”.

Paste your code below:

Created by Mr Suffar

198 of 244

113) Write a program that:

  • Asks the user for a temperature
  • If the temperature is greater than 28, display “T Shirt weather”.
  • If the temperature is between 18 and 28, display “Lovely weather”
  • If the temperature is less than 18, output “It’s cold”

Paste your code on the below:

Created by Mr Suffar

199 of 244

114) Write a program that:

  • Asks the user to enter a Ph value as a float. Display alkaline if the value is between 7 and 14. Display Acidic if its between 0 and 6. Display Neutral if its 7. Display “Invalid pH” if the number entered is outside the Ph scale.

Paste your code on the below:

Created by Mr Suffar

200 of 244

Task 115

Answer:

Answer:

Created by Mr Suffar

201 of 244

Task 116

Paste your code below:

Created by Mr Suffar

202 of 244

Task 117

Paste your code below:

Created by Mr Suffar

203 of 244

Task 118

Paste your code below:

Created by Mr Suffar

204 of 244

119) Create a program that allows the user to convert between different units:

  • Ask the user for a number.
  • Ask the user what unit is the data currently in.
  • Ask the user what unit do they want to convert to.
  • Convert between Bits, Bytes and Kilobytes.

There are 8 bits in 1 bye, and 1000 bytes in 1 Kilobytes.

Paste your code on the below:

Created by Mr Suffar

205 of 244

Homework

Created by Mr Suffar

206 of 244

  • Explain what is meant by syntax and logic errors.
  • Identify syntax and logic errors in code.
  • Prepare a python program using modulo to distinguish between odd and even numbers.

If statement part 3

Lesson 6

Thursday, June 15, 2023

Lesson objectives…

Created by Mr Suffar

207 of 244

Lesson theory

Created by Mr Suffar

208 of 244

Syntax error

Syntax Error: When you break the rules of the programming language.

Examples:

  • Iff name == “hello”:

  • if name != “hello”

  • else::

Created by Mr Suffar

209 of 244

Cold call – Find the syntax errors

Spot the syntax errors in the code

Should be input

Missing colon :

Missing “”

Missing parenthesis )

Created by Mr Suffar

210 of 244

Logic Error

Logic Error: When your program runs however it produces an unexpected results.

Examples:

  • Using incorrect comparison operators such as > instead of < .
  • Using incorrect arithmetic operators such as - instead of + .
  • Using incorrect Boolean operators such as “AND” instead of “OR”

Created by Mr Suffar

211 of 244

Cold call – Find the logic errors

Spot the logic errors in the code

Should be and

Should be <

Created by Mr Suffar

212 of 244

Cold call – Find the logic errors

Spot the logic errors in the code

Should be <= because the user could have the exact amount of mealcost.

Created by Mr Suffar

213 of 244

COLD CALL – FINDING ERRORS

Identify the errors and whether they are syntax or logic

Syntax error: Double

Brackets missing ))

Logic error: must be > instead of <

Logic error: must be < instead of >

Syntax error: Missing Quotation mark "

Created by Mr Suffar

214 of 244

Tasks

Complete tasks

Created by Mr Suffar

215 of 244

120. Copy the code below, run it and test it, then explain the purpose of the program/what the program does.

Explain the purpose of the code below:

number = int(input("Enter a number"))

if number % 3 == 0 and number % 5 == 0:

print(number, "is divisible by both 3 and 5")

else:

print(number, "is not divisible by both 3 and 5")

Answer:

Created by Mr Suffar

216 of 244

121. The program below must: Ask the user for a positive number, if the number is positive, it displays positive and whether it is even or odd. If its not positive, it displays not a positive number.

Copy the code below, run it and fix the errors.

num = int(input"Enter a positive number"))

# Nested if statement

if num < 0:

print("Number is positive")

if num % 2 == 0

print("Number is even")

else

print("Number is odd"

else:

print("Number is not positive)

Paste the correct version below:

Created by Mr Suffar

217 of 244

122. Create a program that: Calculates the number of weeks and days from a given number of days then displays it on the screen in a full sentence.

days = ____(____("Enter the number of days"))

# Integer division and remainder calculation

weeks = days // ___

remaining_days = days __ 7

print("Weeks:", ____)

print("Remaining Days:", ________)

Copy the code above, fill the gaps then paste your code below:

Created by Mr Suffar

218 of 244

123. Ask the user for a number.

Display if the number is odd or even.

Hint: Use MODULO %

Paste your code below:

Created by Mr Suffar

219 of 244

124) The following formula is used to convert Celsius to Fahrenheit: Y°F=(X°C × 9/5) + 32

The following formula is used to convert Fahrenheit to Celsius: X°C=(Y°F − 32) × 5/9

represents the value in Celsius and Y represent the value in Fahrenheit.

Use the formula above to create an algorithm that converts Celsius to Fahrenheit.

Your algorithm must:

  • Ask the user whether they want to convert from (Celsius to Fahrenheit) or (Fahrenheit to Celsius)
  • Ask the user for the temperature.
  • Converts the temperature into what the user picked.
  • Displays the answer in a full sentence.

Paste your code below:

Created by Mr Suffar

220 of 244

125) Create a program that:

  • Asks the user if it’s August or not.
  • If they answer yes, display “Yay summer holiday”
  • Otherwise ask them if it’s the weekend.
  • If the answer is yes, display “Yay no school”.
  • Otherwise display, “Bad luck, you have school today”.
  • Use nested if statement (An if statement inside another if statement”)

Paste your code below:

Created by Mr Suffar

221 of 244

126) Create a program that: Asks the user to enter a decimal number. Round the decimal number to the nearest whole number then display the number and also display whether that number is even or odd.

Paste your code below:

Created by Mr Suffar

222 of 244

127) Create a program that:

  • Asks the user enter today’s day (Monday, Tuesday etc.…)
  • Displays “Yay it’s the weekend” if the user enters Saturday or Sunday.
  • Displays how many days left until the weekend. (Example: “5 days until the weekend if the user enters Monday”)
  • Use nested if statement (if statement inside another if statement)

Paste your code below:

Created by Mr Suffar

223 of 244

128) When a character takes damage in a game, their health bar goes down.

The health bar starts to increase (regenerate) 5 seconds from the last time a player was hit and by 1% per second. At 100%, the health bar has 500 health points.

Create an algorithm that:

  • Asks the user how many health points remained after they

received the last attack (out of 500)

  • Asks them how many seconds ago did they get hit.
  • Calculates the user’s current health points out of 500.
  • Calculates the user’s health point as a percentage % out of 100%.
  • The current health points must NOT be above 500.

Paste your code below:

Created by Mr Suffar

224 of 244

129) Code the following flowchart in python:

Yes

No

No

Paste your code below:

Created by Mr Suffar

225 of 244

130) Code the following flowchart in python:

Paste your code below:

Created by Mr Suffar

226 of 244

131) Tom wants to hire a car. He wants to know how much it will cost him to drive to a different city and back.

  • The hiring company charges the following:
  • A booking fee of £5
  • There is no booking fee for customers who own a membership card.
  • First mile costs = £2
  • Rest of the miles cost: 0.25 per mile.
  • Tom also needs to fill the car with Diesel, the car uses approximately £0.5 in diesel per mile.

Create an algorithm that:

  • Asks the user how many miles are they going to travel.
  • Asks the user if they have a membership card.
  • Calculates the total cost of the journey. (remember to deduct the booking fee if they have a membership card)

Paste your code below:

Created by Mr Suffar

227 of 244

Task 132

Paste your code below:

Created by Mr Suffar

228 of 244

Task 133

?

?

?

?

?

Created by Mr Suffar

229 of 244

Task 134

Paste your code below:

Created by Mr Suffar

230 of 244

Task 135

Paste your code below:

Created by Mr Suffar

231 of 244

Task 136

Paste your code below:

Created by Mr Suffar

232 of 244

Task 137

Paste your code below:

Created by Mr Suffar

233 of 244

Task 138

Paste your code below:

Created by Mr Suffar

234 of 244

Task 139

Paste your code below:

Created by Mr Suffar

235 of 244

Task 140

Paste your code below:

Created by Mr Suffar

236 of 244

Task 141

Paste your code below:

Created by Mr Suffar

237 of 244

Task 142

?

?

Created by Mr Suffar

238 of 244

Task 143

Paste your code below:

Created by Mr Suffar

239 of 244

Task 144

Paste your code below:

Created by Mr Suffar

240 of 244

Task 145

Paste your code below:

Created by Mr Suffar

241 of 244

Task 146

Paste your code below:

Created by Mr Suffar

242 of 244

Task 147

Paste your code below:

Created by Mr Suffar

243 of 244

Homework

  • Revise for end of unit assessment

Created by Mr Suffar

244 of 244

End of unit test

Created by Mr Suffar