Intro to Programming Key concept l Logic is

  • Slides: 30
Download presentation
Intro to Programming

Intro to Programming

Key concept l Logic is a method of reasoning and a system of principles

Key concept l Logic is a method of reasoning and a system of principles used to build arguments and reach conclusions.

Algorithm

Algorithm

l Algorithm - A list of steps to finish a task.

l Algorithm - A list of steps to finish a task.

Program

Program

l Program - An algorithm that has been coded into something that can be

l Program - An algorithm that has been coded into something that can be run by a machine.

l How do you suppose that robots know how to do the things that

l How do you suppose that robots know how to do the things that they do? Do they have brains that work the same way that ours do?

Lynx - Amazon Alexa Enabled Smart Home Robot l It is capable of voice

Lynx - Amazon Alexa Enabled Smart Home Robot l It is capable of voice interaction, music playback, making to-do lists, setting alarms, streaming podcasts, playing audio books, and providing weather, traffic, sports, and other real-time information, such as news.

Yu. Mi Collaborative Robot The single-arm Yu. Mi is ABB’s most agile and compact

Yu. Mi Collaborative Robot The single-arm Yu. Mi is ABB’s most agile and compact collaborative robot yet, and can be easily integrated into any production environment.

Computer Programming? l What is programming? l l l The process of writing, testing,

Computer Programming? l What is programming? l l l The process of writing, testing, and maintaining the source code of computer programs. Telling the computer what to do Why learn to program? l l l Develops logic and problem-solving skills Improves attention to detail It’s fun!

But I’m Not a Geek! l Until recently, programming required knowledge of computer language

But I’m Not a Geek! l Until recently, programming required knowledge of computer language syntax

Anyone Can Program! l New tools, like Scratch, allow ANYONE to create computer programs

Anyone Can Program! l New tools, like Scratch, allow ANYONE to create computer programs without learning complicated syntax.

Scratch Syntax: Part 1 Algebra-Geometry

Scratch Syntax: Part 1 Algebra-Geometry

Statements l l In programming, a statement is simply a directive that tells the

Statements l l In programming, a statement is simply a directive that tells the computer to do something. Think of it as a command or an instruction. In Scratch, any block whose label reads like a command is a statement.

Boolean Expressions l l Sometimes, you only want a statement to be executed under

Boolean Expressions l l Sometimes, you only want a statement to be executed under certain conditions. Such conditions are defined in terms of Boolean expressions. In programming, a Boolean expression is an expression that is either true or false. In Scratch, any block shaped like an elongated diamond is a Boolean expression.

Boolean Expressions l One such block is: After all, it is either true that

Boolean Expressions l One such block is: After all, it is either true that the mouse button is down or it is false. l l Another such block is: After all, it is either true that some number is less than another number or it is false. With Boolean expressions can we construct conditions.

Conditions l l l In programming, a condition is something that must be true

Conditions l l l In programming, a condition is something that must be true in order for something to happen. A condition is thus said to "evaluate to true" or "evaluate to false. " In Scratch, any block whose label says "if, " "when, " or "until" is a sort of conditional construct.

Conditions l If Construct: Instruct a sprite to say hello only if, say, the

Conditions l If Construct: Instruct a sprite to say hello only if, say, the user has depressed the mouse button: l If-Else Construct: Instruct a sprite to say hello or goodbye, depending on whether the user has depressed the mouse button:

Conditions l When Construct: Instruct a sprite to do something when an event occurs:

Conditions l When Construct: Instruct a sprite to do something when an event occurs: l When Construct: Instruct a sprite to wait to do something until a condition is true:

Loops l l In programming, a loop can induce multiple executions of statements. In

Loops l l In programming, a loop can induce multiple executions of statements. In Scratch, any block whose label begins with "forever" or "repeat" is a looping construct.

Variables l l In programming, a variable is a placeholder for some value, much

Variables l l In programming, a variable is a placeholder for some value, much like x and y are popular variables in algebra. In Scratch, variables are represented with blocks shaped like elongated circles, uniquely labeled by you.

Threads l l In programming, a thread is like a miniprogram within a program

Threads l l In programming, a thread is like a miniprogram within a program that can execute at the same time as other threads. In Scratch, any block whose label begins with "when" essentially demarks the start of a thread.

Events l l An event is a signal from one thread to another. Blocks

Events l l An event is a signal from one thread to another. Blocks whose labels begin with "broadcast" signal events whereas blocks whose labels begin with "when" handle events.

Pac Man and Pong l Games like Pac Man use Threads l A Variable

Pac Man and Pong l Games like Pac Man use Threads l A Variable could be added to Pong

Human Algorithms l With human algorithms we can rely on: l l l Intuition

Human Algorithms l With human algorithms we can rely on: l l l Intuition Initiative Prior knowledge Learning from experience Independent decision making

Human Algorithms Computers do not have these things. Mention algorithms that you execute in

Human Algorithms Computers do not have these things. Mention algorithms that you execute in your daily life

Try writing an algorithm for the following snowman

Try writing an algorithm for the following snowman

1. Draw 3 circles on top of each other. The top circle is the

1. Draw 3 circles on top of each other. The top circle is the smallest, the middle circle is middle sized and the bottom circle is the largest 2. On top of the top circle, draw a square with a line underneath it extending out at the sides of the square 3. In the top area of the bottom circle draw a coloured small circle 4. In the centre of the middle circle draw two small coloured circles 5. In the top circle, draw two small solid circles side by side in the upper part of the circle 6. In the top circle, draw three small circles side by side in the bottom part of the circle in a U shape. 7. In the top circle, draw a left facing right angled triangle in the centre of the circle with the base twice the side of the height. 8. On the right hand side of the middle circle, draw a line facing north east direction and at the end of the line draw a small hexagon 9. On the left hand side of the middle circle, draw a line facing north west direction and at the end of the line draw a small hexagon

Try writing an algorithm for the following picture

Try writing an algorithm for the following picture

1. 2. 3. 4. In the centre of the page draw a rectangle about

1. 2. 3. 4. In the centre of the page draw a rectangle about 3 mm high 3 cm wide. At the midpoint of the top side of rectangle draw a line upwards 5 cm in length. Draw a rectangle 4 cm high 2 cm wide with the midpoint of the bottom side touching the top of the upwards line. Draw 3 circles inside the top rectangle all 1 cm in diameter that are centred horizontally across the rectangle and spaced evenly vertically in the rectangle