Download presentation
Presentation is loading. Please wait.
1
Python Selection
2
Selection What does Selection mean? biscuits = 3
3
Selection Example: If the bulb is broken Then choose another
Could be followed with an Else clause: choose another bulb Else choose the first bulb
4
If Statement - Analysis
If the bulb is broken Then choose another Conditions always evaluate to True or False Boolean Value More than one condition can be tested Nesting to achieve different outcomes Condition Action
5
Python – If Statement == != < > >= <= Relational operator
If keyword Colon terminates the statement Condition to test Relational operator Meaning == Equal to != Not equal to < Less than > Greater than >= Greater than or Equal to <= Less than or Equal to All statements matching the TRUE condition are indented
6
Activity 1 Test Score Grades (save as Test Scores) Extension
Write a program to give the grade for a given mark in a test. The grades are <50 – Fail 50 – 69: Level 3 : Level 2 : Level 1 The code has been started for you but it contains an error can you spot what it is? Extension 1. Allow the user to enter their score Give an appropriate message if they don’t enter a number between 1 and 100
7
Activity 2 Happiness Calculator (save as Happiness Calculator)
Write a program to work out a happiness rating for a value input by the user 1=Unhappy; 2-4 =Sad; 5-7 = OK; 8-9=Happy; 10= Very happy Give an appropriate message if they don’t enter a number between 1 and 10 4. Mud In a Can You are starting a new business called Mud in a Can. You have discovered that there is a local source of mud that has great therapeutic properties and can be used in face packs. Write a program that: o Lets the customer enter the height and radius of the can o Computes the volume of the can o Mud retails for £1.79 per cubic centimetre (cc) o Display the cost to the customers for the can of mud o Include error checking so that only positive values (integer or real numbers) can be entered for the height and radius 5. Pizza Tonight Your Mum calls whilst you are out and asks you to get frozen pizzas for dinner from the Seven11 store on your way home. · If they are out of stock and Domino’s is open, you can get fresh pizza from Dominos. Otherwise just get chicken wings from the hot food counter at the Seven11. · · Complete the code to display what you are getting for dinner tonight. Extension: · Realising that you might not have enough money, your mum calls you back and tells you to go to Steve’s house for your dinner if you don’t have enough money to buy the food. Pizza costs £2.79; Hot Chicken £4.50. · Include additional statements to find out how much money you have and take appropriate action in each of the shops.
8
Activity 3 Mud In a Can (Save as Mud in Can)
You are starting a new business called Mud in a Can. You have discovered that there is a local source of mud that has great therapeutic properties and can be used in face packs. Write a program that: Lets the customer enter the height and radius of the can Computes the volume of the can (formula is V = π r2 h) Mud retails for £1.79 per cubic centimetre (cc) Display the cost to the customers for the can of mud Extension Include error checking so that only positive values (integer or real numbers) can be entered for the height and radius 4. Mud In a Can You are starting a new business called Mud in a Can. You have discovered that there is a local source of mud that has great therapeutic properties and can be used in face packs. Write a program that: o Lets the customer enter the height and radius of the can o Computes the volume of the can o Mud retails for £1.79 per cubic centimetre (cc) o Display the cost to the customers for the can of mud o Include error checking so that only positive values (integer or real numbers) can be entered for the height and radius 5. Pizza Tonight Your Mum calls whilst you are out and asks you to get frozen pizzas for dinner from the Seven11 store on your way home. · If they are out of stock and Domino’s is open, you can get fresh pizza from Dominos. Otherwise just get chicken wings from the hot food counter at the Seven11. · · Complete the code to display what you are getting for dinner tonight. Extension: · Realising that you might not have enough money, your mum calls you back and tells you to go to Steve’s house for your dinner if you don’t have enough money to buy the food. Pizza costs £2.79; Hot Chicken £4.50. · Include additional statements to find out how much money you have and take appropriate action in each of the shops.
9
Activity 4 Part 1 - Pizza Tonight (Save as Pizza Tonight)
Your Mum calls whilst you are out and asks you to get frozen pizzas for dinner from the Seven11 store on your way home. If they are out of stock and Domino’s is open, you can get fresh pizza from Dominos. Otherwise just get chicken wings from the hot food counter at the Seven11. Download the starter code rom this link: Complete the code to display what you are getting for dinner tonight. Extension: Realising that you might not have enough money, your mum calls you back and tells you to go to Steve’s house for your dinner if you don’t have enough money to buy the food. Pizza costs £2.79; Hot Chicken £4.50. Include additional code to find out how much money you have and take appropriate action in each of the shops. 5. Pizza Tonight Your Mum calls whilst you are out and asks you to get frozen pizzas for dinner from the Seven11 store on your way home. · If they are out of stock and Domino’s is open, you can get fresh pizza from Dominos. Otherwise just get chicken wings from the hot food counter at the Seven11. · · Complete the code to display what you are getting for dinner tonight. Extension: · Realising that you might not have enough money, your mum calls you back and tells you to go to Steve’s house for your dinner if you don’t have enough money to buy the food. Pizza costs £2.79; Hot Chicken £4.50. · Include additional statements to find out how much money you have and take appropriate action in each of the shops.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.