Procedures Programming Guides.

Slides:



Advertisements
Similar presentations
Follow the man….. Read the phrases on the shimmering neon lights and write down the correct economic term to match that phrase.
Advertisements

Adapted from John Zelle’s Book Slides
Modules and Objects Introduction to Computing Science and Programming I.
1 Functions Samuel Marateck © A function is a set of statements that can be referred by the function name. To start writing a function. 1. In the.
CS1061 C Programming Lecture 2: A Few Simple Programs A. O’Riordan, 2004.
Chapter 2 Writing Simple Programs
Understanding the Mainline Logical Flow Through a Program (continued)
PYTHON: LESSON 1 Catherine and Annie. WHAT IS PYTHON ANYWAY?  Python is a programming language.  But what’s a programming language?  It’s a language.
Python quick start guide
Noadswood Science,  To know the basics of Python coding and decoding Monday, September 07, 2015.
A Level Computing#BristolMet Session Objectives U2#S6 MUST identify different data types used in programming aka variable types SHOULD describe each data.
Munster Programming Training
Python November 28, Unit 9+. Local and Global Variables There are two main types of variables in Python: local and global –The explanation of local and.
Functions and subroutines – Computer and Programming.
Module 3 Fraser High School. Module 3 – Loops and Booleans import statements - random use the random.randint() function use while loop write conditional.
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
Hey, Ferb, I know what we’re gonna do today! Aims: Use formatted printing. Use the “while” loop. Understand functions. Objectives: All: Understand and.
Python Functions.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
I Power Higher Computing Software Development Development Languages and Environments.
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
INLS 560 – F UNCTIONS Instructor: Jason Carter.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 5 Repetition.
GCSE Computing: Programming GCSE Programming Remembering Python.
Agenda  Take up homework  Loops - Continued –For loops Structure / Example involving a for loop  Storing Characters in variables  Introduction to Functions.
A Python Tour: Just a Brief Introduction "The only way to learn a new programming language is by writing programs in it." -- B. Kernighan and D. Ritchie.
Scion Macros How to make macros for Scion The Fast and Easy Guide.
FOR LOOPS "LOOP FOR A SET NUMBER OF TIMES.". FOR ( START_VALUE; END_VALUE; INCREMENT_NUMBER ) { //YOUR_CODE_HERE } So after the word "for" (in lowercase)
PYTHON FUNCTIONS. What you should already know Example: f(x) = 2 * x f(3) = 6 f(3)  using f() 3 is the x input parameter 6 is the output of f(3)
For Loop GCSE Computer Science – Python. For Loop The for loop iterates over the items in a sequence, which can be a string or a list (we will discuss.
Chapter 1: Introduction to Computers and Programming.
Getting Started With Python Brendan Routledge
Functions. What is a Function?  We have already used a few functions. Can you give some examples?  Some functions take a comma-separated list of arguments.
Chapter 2 Writing Simple Programs
Introduction to Computing Science and Programming I
what is computer programming?
A Python Tour: Just a Brief Introduction
Introduction to Programming
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Introduction Python is an interpreted, object-oriented and high-level programming language, which is different from a compiled one like C/C++/Java. Its.
IF statements.
Think What will be the output?
Computer Science and an introduction to Pascal
When I want to execute the subroutine I just give the command Write()
Chapter 3 Simple Functions
Python 17 Mr. Husch.
Functions and Procedures
Escape sequences: Practice using the escape sequences on the code below to see what happens. Try this next code to help you understand the last two sequences.
Data Structures – 1D Lists
Multiple Selections (ELIF Statements)
Introduction to Programming
Selection Statements.
Python 17 Mr. Husch.
Inputs and Variables Programming Guides.
Elements of a Python Program
For Loops (Iteration 1) Programming Guides.
Topics Introduction to Functions Defining and Calling a Function
Introduction to Computer Science
Chopin’s Nocturne.
CSE 231 Lab 4.
Python Functions.
Introduction to Programming
Continuous & Random September 21, 2009.
Python Conditionals: The if statement
Starter Which of these inventions is: Used most by people in Britain
Chapter (3) - Procedures
What you need to do… Drag the pieces of code into the correct order like you can see in the EXAMPLE below. print ( “ int input ) = + Hello world chr ord.
Problem to solve Given four numbers, days, hours, minutes, and seconds, compute the total number of seconds that is equivalent to them. For example, 0.
Introduction Procedures Results Conclusion Methods References
Week 7 - Friday CS 113.
Presentation transcript:

Procedures Programming Guides

Procedures Introduction to Procedures As we start writing larger programs with more and more lines of code, finding errors and editing the code can become more and more difficult. We can get lost in the hundreds of lines of code. To over come this, ‘sensible programmers’ make use of procedures.

Procedures Procedures in Python A procedure can be thought of as a mini program or a subroutine. It sits in the background waiting to be called. #Main Program: Print(“Welcome to the 10 Times Table”) timestable() #program ends input() #times table procedure: def timestable(): for x in range(10) print(x, “times 10 is”, x*10) Calling the Procedure

Procedures Setting up a Procedure Procedures sit at the top of our code. The are declared using the ‘def’ command. They are then given a name. E.G.: def procedure1(): The code for the procedure is then written ‘indented’ underneath. Notice the brackets and colon!

Procedures An Example of a Procedure The Procedure The Main Program When programs with procedures are run, the procedures are ignored and the main program is executed. When a procedure is called in the main program, the procedure is executed. After the lines of code in the procedure are executed, the main program is resumed. The Procedure The Main Program

Procedures Local Variables and Procedures In programing there are two main classifications of variables: Global and Local. A global variables is one which is defined in the main program. A local variable is one which is defined in the procedure / function Here the local variable is being printed (due to the procedure call). Then the global variable is being printed (due to the print statement). Local Variable Global Variable

Procedures Local Variables and Procedures In programing there are two main classifications of variables: Global and Local. If a procedure / function doesn’t assign its own variable, the function will use the global variable: Here a global variable is being assigned (as the assignment is being done in the main program) Then, as the procedure / function doesn’t assign its own variable, it uses the global variable ‘s’. Global Variable Global Variable