Slides badge

Expressions and constructs

Learning Intentions

  • Develop a computer program using selection and variables

Success Criteria

  • I can write the Python code to create a computer program

What is this unit about?

  • This unit is focused on teaching you the very basics of computer programming.
  • Each year you will study computer programming (if you pick computing) and this will give you the foundations that you need for S3 and beyond.
  • Within this unit, you will be using the Code Club examples to work through and help you develop programming skills.

What is this unit about?

Trinket or IDLE

  • Completing the Code Club tasks normally involves using an online Python editor called Trinket.
  • However, you can choose to use Python IDLE on your local computer instead of Trinket if you prefer. The main reason for doing this is performance.

Your project

  • At the very end of the unit you will be given a small project that will allow you to show off your programming skills.
  • If you choose to take computing into S3, the programming tasks will be tougher but with skills you obtain in S2 you will be able to tackle these no problem.

Constructs

  • In a programming language, we have several built-in constructs.
  • A construct is a block of code that carries out a set of instructions in sequence such as creating a variable or repeating something so many times
  • You've come across quite a few in Scratch:
    • Variables (e.g. Points, Lives, Time)
    • Selection (If)
    • Loops (Forever, Repeat)

Constructs

  • In a programming language, we have several built-in constructs.
  • A construct is a block of code that carries out a set of instructions in sequence such as creating a variable or repeating something so many times
  • You've come across quite a few in Scratch:
    • Variables (e.g. Points, Lives, Time)
    • Selection (If)
    • Loops (Forever, Repeat)
  • In S1 you will be looking at the two underlined constructs.

Expressions

  • In a programming language, an expression is something that can be evaluated to another value.
  • For example, a condition evaluates to true or false whereas addition evaluates to one number plus another.
  • An example of a condition in Scratch is:

Python variables

  • In Scratch you could declare a variable by giving it a name. 
  • When the game or animation starts, the variable is given a value (this is known as initialisation).
time = 30

Python variables

  • In Python, we can simply write the variable name (time) and give it the value we want (30)
time = 30

Logic

  • Computers are logical machines that work by comparing things.
  • In Scratch, you have come across using conditions.
  • You may also have come across the AND and OR blocks in Scratch.
  • All of this logic can be represented with a Venn Diagram.
  • We can assume in most cases, a variable A is being used

Logic

Logic

51

Logic

51

34

Logic

51

34

21

Logic

51

34

21

37

Logic

51

34

21

37

91

Logic

51

34

21

37

91

25

Logic

51

34

21

37

25

91

Crow

Logic

51

34

21

37

25

91

Crow

AND

  • AND is a logical operator that gives us true when both A and B are true.
  • For example:
    • 55 > 43 AND < 200 returns true
    • 55 > 43 AND < 10 returns false

Or

  • OR is another logical operator that gives us true when both A and B are true, or one of them is true.
  • For example:
    • 55 > 43 OR < 20 returns true
    • 55 > 43 OR < 10 returns true
    • 43 > 55 OR < 10 returns false

Not

  • NOT reverses a boolean value, so true becomes false and false becomes true.
  • Since NOT is never true when A is true, it is represented by the diagram below which shows everything outside of A is the same as NOT A.
  • Assume A is 43, any number that isn't 43 is NOT A.

Not A and B

  • The following diagram shows NOT A AND B, that is anything that is not A and is B.
  • For example, if A is any number greater than 40 and B is any number greater than 10, if the number provided was 12 then this would evaluate to true, since it's not greater than 40 but is greater than 10.

Complete the logic worksheet on Google Classroom.

 

Use the Venn Diagrams to help you.

Task

Get started with the Code Club Projects tasks at

 

bit.ly/3ExKiab

 

Work your way through the tasks and ask for help when needed

Task

Lesson review

I have completed the first task

I have completed the first two tasks

I have completed at least the first three tasks

Presentation Overview
Close
JB
Expressions and Constructs
© 2020 - 2024 J Balfour
21:27 | 03-12-2024
Join Live Session
Go Live
Start Remote
Save Progress
Slideshow Outline
Presenter Mode
Generate Quiz
Generate Lesson Plan
Widget Screen
Canvas Controls
Fullscreen
Random Selector
Timer
Volume Meter
Binary Converter
Python Editor
Show Knox 90
Provide Feedback
Help
!
Keywords
    DragonDocs Management
    Random selector
    Sections
      Binary conversion
      Denary to binary conversion
      Binary to denary conversion
      Feedback 👍
      Accessibility

      Apply a filter:

      ×
      Loading
      All slideshow files