Programming - ICT Teacher

Download Report

Transcript Programming - ICT Teacher

PROGRAMMING
In
Lesson 4
RECAP
 Complete the starter activity
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.
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
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
>>> True
>>> False
>>> True
>>> False
THE IF STATEMENT
 The basic if statement is this.
 If statements are one of the building blocks of programming.
IF STATEMENTS
 Copy this on the board. – save it in lesson 4 as my_if
 Run the program
IF…ELSE … STATEMENTS
Add these 2 lines
Copy this on the board. – save it in lesson 4 as my_else
Student to explain?
INDENTING
Try this?
What happens now with the IF statement Block
INDENTING
Try this?
What happens now with the IF statement Block
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.
THE TRUTH TABLES
 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
THE SOLUTION
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
PLENARY
 Try the plenary quiz in my documents -> python -> folder 4
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….