Python Selection.

Slides:



Advertisements
Similar presentations
Chapter 4 - Control Statements
Advertisements

Dry Run You can test your program without using a computer by dry running it on paper You act as the computer – following the instructions of the program,
 Control structures  Algorithm & flowchart  If statements  While statements.
1 9/26/08CS150 Introduction to Computer Science 1 Logical Operators and if/else statement.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
1 Arithmetic in C. 2 Type Casting: STOPPED You can change the data type of the variable in an expression by: (data_Type) Variable_Name Ex: int a = 15;
The If/Else Statement, Boolean Flags, and Menus Page 180
1 9/28/07CS150 Introduction to Computer Science 1 Logical Operators and if/else statement.
From Scratch to Python Learn to program like the big boys / girls!
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
26/10/ Selection Nested If structures & Complex Multiple Conditions.
Writing Program Code in BASIC Write a program to prompt for and accept values into TWO variables, numx and numy. The program should square the value stored.
Making Decisions (True or False) Relational Operators >greater than =greater than or equal to
PROGRAMMING In Lesson 2. STARTER ACTIVITY Complete the starter activity in your python folder – lesson 2 Now we will see how you got on and update your.
22/11/ Selection If selection construct.
Chapter 3: Branching and Program Flow CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
Agenda Basic Logic Purpose if statement if / else statement
Decision Structures and Boolean Variables. Sequence Structures Thus far, we’ve been programming “sequence structures” Thus far, we’ve been programming.
Decision Structures, String Comparison, Nested Structures
31/01/ Selection If selection construct.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)
Slide 1 Chapter 4 The If…Then Statement  Conditional control structure, also called a decision structure  Executes a set of statements when a condition.
Selection UCT Department of Computer Science Computer Science 1015F Hussein Suleman March 2009.
© 2006 Lawrenceville Press Slide 1 Chapter 5 The If…Then Statement (One-Way)  Conditional control structure, also called a decision structure  Executes.
Component 1.6.
GCSE COMPUTER SCIENCE Practical Programming using Python
Introduction to Decision Structures and Boolean Variables
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter 4 Selections © Copyright 2012 by Pearson Education, Inc. All Rights Reserved.
Computer Information Technology Section 6-17
Whatcha doin'? Aims: To start using Python. To understand loops.
More on the Selection Structure
Chapter 4 The If…Then Statement
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
COMP 14 Introduction to Programming
Making Choices with if Statements
Scratch – Simple Programming
CHAPTER 4 Selection CSEG1003 Introduction to Computing
IF statements.
Chapter 4: Control Structures
Selection UCT Department of Computer Science Computer Science 1015F
Control Statement Examples
Selection CIS 40 – Introduction to Programming in Python
Introduction to Programming
Conditions and Ifs BIS1523 – Lecture 8.
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Selection (IF Statements)
Intro to Nested Looping
If selection construct
3 Control Statements:.
The while Looping Structure
Introduction to Programming
If selection construct
Selection Control Structure
Conditional and iterative statements
Intro to Nested Looping
Adding Intelligence Check for the presence or absence of a condition in the environment Take the appropriate actions Involves making a choice (to do or.
Flowcharts and Pseudo Code
Programming Concepts and Database
CS2011 Introduction to Programming I Selections (I)
Lecture Notes – Week 2 Lecture-2
Programming In Lesson 4.
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
CHAPTER 5: Control Flow Tools (if statement)
Making decisions with code
Introduction to Programming
Data Types and Maths Programming Guides.
The while Looping Structure
Iteration – While Loops
Presentation transcript:

Python Selection

Selection What does Selection mean? biscuits = 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

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

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

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 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 Give an appropriate message if they don’t enter a number between 1 and 100

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.

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.

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: https://bit.ly/2Gj5Zhc 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.