Introduction to Python Selection Selection What does Selection

  • Slides: 9
Download presentation
Introduction to Python Selection

Introduction to Python Selection

Selection What does Selection mean? Introduction to Python biscuits = 3

Selection What does Selection mean? Introduction to Python biscuits = 3

Selection Example: Introduction to Python If the bulb is broken Then choose another Could

Selection Example: Introduction to Python If the bulb is broken Then choose another Could be followed with an Else clause: If the bulb is broken Then choose another bulb Else choose the first bulb

If Statement - Analysis Condition Introduction to Python If the bulb is broken Then

If Statement - Analysis Condition Introduction to Python If the bulb is broken Then choose another v v Action Conditions always evaluate to True or False Boolean Value More than one condition can be tested Nesting to achieve different outcomes

Python – If Statement If keyword terminates Introduction to Colon Python Condition to test

Python – If Statement If keyword terminates Introduction to Colon Python Condition to test All statements matching the TRUE condition are indented Relational operator == != < > >= <= the statement Meaning Equal to Not equal to Less than Greater than or Equal to Less than or Equal to

Activity 1 Test Score Grades (save as Test Score to Python Write a program

Activity 1 Test Score Grades (save as Test Score to Python Write a program to give the Introduction grade for a given mark in a test. The grades are <50 – Fail 50 – 69: Level 3 70 - 89 : Level 2 90 - 100: 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 2. Give an appropriate message if they don’t enter a number between 1 and 100

Activity 2 Happiness Calculator (save as Happiness Calculator) to Python Write a program to

Activity 2 Happiness Calculator (save as Happiness Calculator) to Python Write a program to work out a Introduction 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

Activity 3 Mud In a Can (Save as Mud in Can) Introduction You are

Activity 3 Mud In a Can (Save as Mud in Can) Introduction You are starting a new business called Mud intoa Python 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 = π r 2 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

Activity 4 Part 1 - Pizza Tonight (Save as Pizza Tonight) Your Mum calls

Activity 4 Part 1 - Pizza Tonight (Save as Pizza Tonight) Your Mum calls whilst you are out Introduction and asks youto to. Python get frozen pizzas for dinner from the Seven 11 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 Seven 11. Download the starter code rom this link: https: //bit. ly/2 Gj 5 Zhc • 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.