Learning to use a ‘For Loop’ and a ‘Variable’. Learning Objective To use a ‘For’ loop to build shapes within your program Use a variable to detect input.

Slides:



Advertisements
Similar presentations
SCRATCH Lesson Two – Interactive Concepts Using Sensing, Operators, and Variables.
Advertisements

CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
How to Debug VB .NET Code.
Bug Session Two. Session description In this session the use of algorithms is reinforced to help pupils plan out what they will need to program on their.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
Learning to program using Minecraft. Learning Objective Know what Minecraft is and to explain some of it’s uses Build a simple house in creative mode.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
BEGINNER PROGRAMMING Lesson
Introduction to Python
Making a Boat Racing Game in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2010.
THE BIG PICTURE. How does JavaScript interact with the browser?
General Programming Introduction to Computing Science and Programming I.
Unit 1 – Improving Productivity Instructions ~ 100 words per box.
Python Programming Introduction to programming using python.
Mail merge I: Use mail merge for mass mailings Perform a complete mail merge Now you’ll walk through the process of performing a mail merge by using the.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
PHP meets MySQL.
Spreadsheets in Finance and Forecasting Presentation 9 Macros.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
Section 2 Variables National 4/5 Scratch Course. What you should know after this lesson What a variable is Where variables are stored How to get data.
Computer Science 101 Introduction to Programming.
Unit 1 – Improving Productivity Instructions ~ 100 words per box.
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
1 C++ Programming Basics Chapter 2 Lecture CSIS 10A.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
Type accurately challenge! This is a starter activity and should take 2 minutes [ slide 1 ] 1.Can you type out the code in Code Box 2.1 with no errors.
Fill the screen challenge! This is a starter activity and should take 3 minutes [ slide 1 ] 1.Log in to your computer 2.Open IDLE 3.In interactive mode,
PROGRAMMING In Lesson 2. STARTER ACTIVITY Complete the starter activity in your python folder – lesson 2 Now we will see how you got on and update your.
Python Programming Using Variables and input. Objectives We’re learning to use basic knowledge of variables combined with user input. Outcomes Continue.
Grade Book Database Presentation Jeanne Winstead CINS 137.
End of unit assessment Challenge 1 & 2. Course summary So far in this course you have learnt about and used: Syntax Output to screen (PRINT) Variables.
Decision Structures, String Comparison, Nested Structures
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Learning to program a turtle to build different structures.
Using Lists Games Programming in Scratch. Games Programming in Scratch Extension – Using Lists Learning Objectives Create a temporary data store (list)
Python Let’s get started!.
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.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Introduction to Text Based Coding. We’re learning to explore how text based programming works You will display and enter text into a window You will use.
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 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
LO: We’re learning to outline a program using Pseudo Code.
Donor's Choose Starter Instructions by Neely Swygert Teacher-Librarian Gadsden Elementary.
COMPUTER PROGRAMMING Year 9 – lesson 1. Objective and Outcome Teaching Objective We are going to look at how to construct a computer program. We will.
Introducing Python 3 Introduction to Python. Introduction to Python L1 Introducing Python 3 Learning Objectives Know what Python is and some of the applications.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
Introducing Python Introduction to Python.
Whatcha doin'? Aims: To start using Python. To understand loops.
Introduction to Python
Advanced Coding Session 5
By Sanjay and Arvind Seshan
Variables, Expressions, and IO
Learning Objective LO: We’re learning to understand when it is appropriate to use particular data types.
Python I/O.
Number and String Operations
Explain what touch develop is to your students:
ARRAYS 1 GCSE COMPUTER SCIENCE.
Introduction to TouchDevelop
Variables & getting info from the user
How can we tell these aliens apart?
Variables Lesson Outline
Unit 3: Variables in Java
Introduction to Python programming for KS3
How can we tell these aliens apart?
Explain what touch develop is to your students:
Primary School Computing
Presentation transcript:

Learning to use a ‘For Loop’ and a ‘Variable’

Learning Objective To use a ‘For’ loop to build shapes within your program Use a variable to detect input so that the user can pick how many times they would like to repeat

During the last program you made had a lot of lines to write. Can you remember the problem with this? What was the problem?

Getting Started 1.You will need to load up your Minecraft world from the previous lesson. 2.Make sure that you’re able to edit the code you created. It should have been called something like ‘myfirstmovement’ 3.Load up the edit screen!

‘For’…. loop A "For" Loop is used to repeat a specific block of code a known number of times. For example, if we want to check the grade of every student in the class, we loop from 1 to that number. When the number of times is not known before hand, we use a "While" loop.

How it works… Your ‘for loop’ is built up from different sections. You have the variable which is your start number. It is then separated by a comma and your finish number You then finish off with how many steps you will take. This is where the code you wish to repeat appears!

What is a variable… A variable is a location in memory in which you can temporarily store text or numbers It is used like an empty box or the Memory function on a calculator You can choose a name for the box (the “variable name”) and change its contents in your program Some people refer to a variable as a bucket…

Naming our variables A variable name can contain only numbers, letters and underscores A variable name cannot start with a number You can’t use “reserved word” as a variable name – for example class is a reserved word so class = input() will result in a syntax error

Give it a try! This example shows you how to create a straight line of which ever block you have decided to use

Challenge! Use a ‘FOR LOOP’ to build a structure! You will need to try a combination of loops to build different shapes. See if you can build at least 3 rows of blocks. Extension: - Can you put loops with in a loop to build a whole house?

How can I chose the length of my line? Sometimes it’s useful to ask the user to interact with the program. We can save their input into a variable. The lines above will store the length into a variable called LENGTH – What do you think we will do with length?

How can I chose the length of my line? If you have a look at the code above, can you spot where we have used the variable we called on? *HINT IT’S NO LONGER NUMBER 4*

Challenge? Can you create a program which asks for a number Of different variables. This could be height and Width and you can see if you can create a wall for a building….. Requirement: - Use a for loop along with a variable for the length / height

While Loops Sometimes we do not want our program to keep building, we might want to check if we still have the resources to do it. What if we didn’t have enough wood left? We might want to keep building until we run out. This is why we would need to check a condition……. Think about you being in a lesson, you’re working on IT/Computing until the bell goes for the next lesson. We can even use a while loop to check which number we’ve got to. An example is on the next slide.

While Loop This line converts it to a number This lines compares it to see if it’s still less This increases the total by one before it’s checked at the beginning of the while loop

Challenge? Are you able to modify your existing program to make use of the while loop within your program? You should use variables and ask for input before it works.

Finishing Up! Now that you’ve learnt how to use a number of different loops we’re going to print off the code we’ve created and we’re going to comment our code. Commenting code is really important and shows your understanding. To comment your code we’re going to use - - ‘two hypthens’