Download presentation
Presentation is loading. Please wait.
1
Programming In Lesson 4
2
Recap Complete the starter activity
3
Objectives Understand a branching statement (if .. then .. else) Understand about indenting and blocks of statements Able to use a function to create a truth table Outcomes All-Level 4 written code using if..then..else - with help written a truth table in code Most-Level 5 Be able to write a these with little help. Some-Level 6 Independently write these and adapt them and complete one of the extension tasks.
4
Operators Operator What it means Typed in IDLE Displayed + Add to
>>> 4 + 5 >>> 9 - Subtract >>> 5 - 1 >>> 4 * Multiply >>> 7 * 3 >>> 21 / Divide >>> 7 / 4 >>> 1.75 // Whole number division >>> 20 // 3 >>> 6 % Remainder after whole number division >>> 20 % 3 >>> 2 ** To the power of >>> 3 ** 4 >>> 81
5
Condition Operators Operator What it means Example Displayed == Equals
>>> 5 == 4 >>> False != Not equals to >>> 5 != 4 >>> True > Greater than >>> 5 > 4 < Less than >>> 5 < 4 >= Greater than or equals to >>> 5 >= 5 <= Less than or equals to >>> 4 <= 4
6
The If Statement The basic if statement is this.
If statements are one of the building blocks of programming.
7
If statements Copy this on the board. – save it in lesson 4 as my_if
Run the program
8
If…ELSE … statements Add these 2 lines
Teacher to explain each line Copy this on the board. – save it in lesson 4 as my_else Student to explain?
9
Indenting Try this? What happens now with the IF statement Block
Explanation that the print after the else is not indented and it will execute EVERY time the function is called irrespective of the user_input value. Try this? What happens now with the IF statement Block
10
Indenting Try this? What happens now with the IF statement Block
Explanation that the print after the else is not indented and it generate an error message as there is no statement after the IF block Try this? What happens now with the IF statement Block
11
Boolean Operators aka TRUTH TABLES
I could tell you about these….but you would probably forget. Lets write a python program to teach you. Remember Boolean variables can be either True or False. What happens when we get 2 together such as >>> a = True >>> b = False What is the result for a AND b? Back to our program.
12
The truth tables a = get_user_boolean_input ()
Write a program to: Use the get_user_input_boolean function in lesson 4 folder to help you. Open the function and use it in your program such as a = get_user_boolean_input () This asks the user to enter either True or False Display the value of variable a and variable b Display the result of a and b (the operator AND) You will need this program later so save it as Truth_Table_And
13
The solution
14
Truth Table Or Write another program to display the result of a or b
Save it as Truth_Table_Or Amend this program so that it asks the user which table they want to use
15
Plenary Try the plenary quiz in my documents -> python -> folder 4
16
Fun Time Open the Turtle_intro python program and read the comments.
Just have fun or…. Try to create …. A blue box With a green circle in it With your initials on top of the box. An easter egg….
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.