Python - Selection Starter

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

EasyGUI “Probably the Easiest GUI in the world”. Assumptions (Teachers’ Notes) This resources sets out an introduction to using easyGUI and Python
ECS 15 if and random. Topic  Testing user input using if statements  Truth and falsehood in Python  Getting random numbers.
Making Decisions in Python Sec 9-10 Web Design. Objectives The student will: Understand how to make a decision in Python Understand the structure of an.
Using factors to find the prime factorization of a number
Variables –recap-python
Top-Down Design CSC 161: The Art of Programming Prof. Henry Kautz 9/16/2009.
Classes, methods, and conditional statements We’re past the basics. These are the roots.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Chapter 9 IF Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Variables in Java Part 2. ICS-3M1 - Mr. Martens - Variables Part 2 Recall the “int” Data Types When you divide one integer by another – you always get.
From Scratch to Python Learn to program like the big boys / girls!
An Introduction to Textual Programming
Python Programming Using Variables and input. Objectives We’re learning to make use of if statements to enable code to ask questions. Outcomes Build an.
PYTHON CONDITIONALS AND RECURSION : CHAPTER 5 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.
INTRODUCTION TO PYTHON. 1. The 5 operators in Python are: + - * / %
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
Solving Equations Foundation Tier GCSE. Starter Activity – Evaluate when…... Put the cards in order of smallest on the left to largest on the right….when….
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Multiplying and Dividing Decimals by 10, 100, and 1,000
Test 2 Review The test will consist of 3 sections. Section 1 is vocabulary matching. Section 2 is a Rate Per 100 problem. Section 3 is a Unit Rate Problem.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #005 (April somthin, 2015)
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.
Making Decisions uCode: October Review What are the differences between: o BlueJ o Java Computer objects represent some thing or idea in the real.
PHY281Flow ControlSlide 1 Decisions In this section we will learn how to make decisions in a Java program  if Statements  if... else Statements  Comparison.
Once seen, never forgotten!
Variables. Todays Lesson  In todays lesson you are going to:  Learn to use variables  Learn to ask for user input  Learn to save the users response.
Python - Selection Selection means selecting (or choosing) what to do next. Should I cycle to school, or ask for a lift? If it’s a sunny day I might cycle.
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
Logical Operators, Boolean Variables, Random Numbers This template was just too good to let go in one day!
Addition and Subtraction of Fractions
© T Madas. These days no one has the need to manually compute square roots. The algorithm which follows has been put to oblivion by the modern calculator,
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
Solving Equations. What are we going to do if we have non-zero values for a, b and c but can't factor the left hand side? This will not factor so we will.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 3 Decision Trees Conditionals.
Family What is a family? There is no fixed recipe for a family; just a group of people who love and care for one another. Love and care are the most.
Expressions and Order of Operations Operators – There are the standard operators: add, subtract, divide, multiply – Note that * means multiply? (No times.
PYTHON PROGRAMMING Week 3 - Tuesday. STARTER Hour of Code Video.
PERFORMING CALCULATIONS IN SCIENTIFIC NOTATION ADDITION AND SUBTRACTION.
Repetition In today’s lesson we will look at: why you would want to repeat things in a program different ways of repeating things creating loops in Just.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)
Computer Science Up Down Controls, Decisions and Random Numbers.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
Functions. What is a Function?  We have already used a few functions. Can you give some examples?  Some functions take a comma-separated list of arguments.
GCSE COMPUTER SCIENCE Practical Programming using Python Lesson 4 - Selection.
Introduction to Decision Structures and Boolean Variables
GCSE COMPUTER SCIENCE Practical Programming using Python
Whatcha doin'? Aims: To start using Python. To understand loops.
Lesson 1 Learning Objectives
Selection CIS 40 – Introduction to Programming in Python
Decision Structures, String Comparison, Nested Structures
Escape sequences: Practice using the escape sequences on the code below to see what happens. Try this next code to help you understand the last two sequences.
Selection (IF Statements)
COMPUTER PROGRAMMING PYTHON
Repetition Structures
Divide the number in C by 10.
PYTHON: BUILDING BLOCKS Sequencing & Selection
Chapter 3: Selection Structures: Making Decisions
Order of Operations PEMDAS.
Programming In Lesson 4.
Understanding Code Workshop 2.
More Strings.
Hardware is… Software is…
COMPUTING.
Math is Magic!!!! Everyone pick a number – any number you want!
Python Creating a calculator.
Presentation transcript:

Python - Selection Starter Open up Starter Task 1 and Starter Task 2 and complete what it is asking you to do.

Python - Selection Selection means selecting (or choosing) what to do next. Should I cycle to school, or ask for a lift? If it’s a sunny day I might cycle. If it’s raining, I’ll ask for a lift.

Python - Selection Try the following code: answer = int(input(“How many hours a day do you play computer games? “)) if answer < 2: print(“That seems a fairly healthy balance. Well done!”) else: print(“You’re probably good enough by now with all that practice.”)

Python - Selection Notice how the colon (:) is used to say what should happen in each case. Also notice that the indentation is VERY important. Python only knows when your IF statement is finished by looking at the indentation! Try the next program to see what I mean:

Python - Selection Try the following code: answer = int(input(“How many hours a day do you play computer games? “) if answer < 2: print(“That seems a fairly healthy balance. Well done!”) else: print(“You’re probably good enough by now with all that practice.”) print(“Xbox 360s are better than PS3s”)

Python - Selection Sometimes there are more than two options. I could walk OR cycle OR get the bus OR get a lift. As well as IF and ELSE, we can stick an ‘ELSE IF’ (or ELIF) in the middle:

Python - Selection answer = int(input(“How many hours a day do you play computer games? “) if answer < 2: print(“That seems a fairly healthy balance. Well done!”) elif answer < 4: print(“You’re probably good enough by now with all that practice.”) else: print(“Put the controller down and get some fresh air once in a while!”)

Python - Selection You can include an unlimited number of ELIFs if you need to. Try the following:

Python - Selection menu = "What would you like:\n\ 1. A complement?\n\ 2. An insult?\n\ 3. A proverb?\n\ 4. An idiom?\n\ 9. Quit\n" answer = int(input(menu)) if answer == 1: print("You look lovely today!") elif answer == 2: print("You smell funny.") elif answer == 3: print("Two wrongs don't make a right. But three lefts do...") elif answer == 4: print("The pen is mightier than the sword.") elif answer == 9: print("Goodbye!!!")

Python - Selection There are a couple of important bits here: • You can put a line break in your string by using “\n”. • You can continue a line of code by putting a “\” at the end. • If you are testing for equality, use a double equals (is 3x2 == 6?)

Python - Selection < Less Than e.g. 3 < 5 > Greater Than e.g. 5 > 3 <= Less Than Or Equal To e.g. 3 <= 5 5 <= 5 >= Greater Than Or Equal To e.g. 5 >= 3 5 >= 5 != Not Equal To e.g. 5 != 3 3 != 5

Python - Tasks Selection Challenge Try making a calculator. The program will ask for two numbers and then give you a menu, so you can add, subtract, multiply, divide, square either number or find out the power.