A Level Computing#BristolMet Session Objectives#U2 S8 MUST identify the difference between a procedure and a function SHOULD explain the need for parameters.

Slides:



Advertisements
Similar presentations
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Advertisements

Session Objectives# 24 COULD code the solution for an algorithm
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Introduction to a Programming Environment
Main task -write me a program
A452 – Programming project – Mark Scheme
Python quick start guide
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
A Level Computing#BristolMet Session Objectives U2#S6 MUST identify different data types used in programming aka variable types SHOULD describe each data.
CIS Computer Programming Logic
A Level Computing#BristolMet Session ObjectivesU2#S10 MUST describe the difference between constants, local and global variables SHOULD explain why constants.
Invitation to Computer Science, Java Version, Second Edition.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
PROGRAMMING Functions. Objectives Understand the importance of modular programming. Know the role of functions within programming. Use functions within.
A Level Computing#BristolMet Session Objectives U2#S9 MUST identify operators and operands SHOULD describe different types of operator COULD Create an.
Introduction. 2COMPSCI Computer Science Fundamentals.
Algorithmic Recursion. Recursion Alongside the algorithm, recursion is one of the most important and fundamental concepts in computer science as well.
E0001 Computers in Engineering Procedures: subprograms and functions.
Chapter 14 Recursion. Chapter Objectives Learn about recursive definitions Explore the base case and the general case of a recursive definition Learn.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Oct 15, 2007Sprenkle - CS1111 Objectives Creating your own functions.
1 CSE1301 Computer Programming Lecture 12 Functions (Part 1)
Data Structures R e c u r s i o n. Recursive Thinking Recursion is a problem-solving approach that can be used to generate simple solutions to certain.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
Exam 1 Review Instructor – Gokcen Cilingir Cpt S 111, Sections 6-7 (Sept 19, 2011) Washington State University.
I Power Higher Computing Software Development High Level Language Constructs.
A Level Computing#BristolMet Session ObjectivesU2#S12 MUST describe the terms modal and pretty printing in term of input and output facilities. SHOULD.
CSCI-100 Introduction to Computing
Sequencing The most simple type of program uses sequencing, a set of instructions carried out one after another. Start End Display “Computer” Display “Science”
Chapter 15: Recursion. Objectives In this chapter, you will: – Learn about recursive definitions – Explore the base case and the general case of a recursive.
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.
Recursion A function is said to be recursive if it calls itself, either directly or indirectly. void repeat( int n ) { cout
A Level Computing#BristolMet Session Objectives#U2 S3 MUST use/read programme flow charts accurately SHOULD adapt the calculator programme to include a.
Variables  A piece of memory set aside to store data  When declared, the memory is given a name  by using the name, we can access the data that sits.
Functions Part I (Syntax). What is a function? A function is a set of statements which is split off into a separate entity that can be used like a “new.
Recursion. Recursive Methods  A recursive method is a method that calls itself.  General Form of Simple Recursive Methods  Every recursive method has.
GCSE Computing#BristolMet Session Objectives #23 MUST understand what is meant by the programming term iteration SHOULD describe methods of looping used.
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
Chapter 15: Recursion. Recursive Definitions Recursion: solving a problem by reducing it to smaller versions of itself – Provides a powerful way to solve.
Chapter 15: Recursion. Objectives In this chapter, you will: – Learn about recursive definitions – Explore the base case and the general case of a recursive.
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.
 Python for-statements can be treated the same as for-each loops in Java Syntax: for variable in listOrstring: body statements Example) x = "string"
Python – Part 4 Conditionals and Recursion. Conditional execution If statement if x>0:# CONDITION print (‘x is positive’) Same structure as function definition.
CMPT 120 Topic: Searching – Part 2 and Intro to Time Complexity (Algorithm Analysis)
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Getting Started With Python Brendan Routledge
World of Wokcraft The very best in Single pan cooking themed fantasy gaming!
Programming what is C++
3.1 Fundamentals of algorithms
Introduction To Flowcharting
ALGORITHMS & FLOWCHARTING II
Functions.
Do it now activity Green pen activity in books.
Teaching London Computing
Learning to Program in Python
Python I/O.
Log onto a computer first then ….
Cs212: DataStructures Computer Science Department Lab 3 : Recursion.
Coding Concepts (Basics)
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
The structure of programming
The structure of programming
Thinking procedurally
WJEC GCSE Computer Science
Challenge Guide Grade Code Type Slides
Programming Techniques
Lecture 6 - Recursion.
Presentation transcript:

A Level Computing#BristolMet Session Objectives#U2 S8 MUST identify the difference between a procedure and a function SHOULD explain the need for parameters in defining subroutines and apply subroutines to a given program (mulitcalc in Python COULD explain what is meant by recursion and the relative strengths between recursion and iteration Create recursive algorithm and compare an iterative version in Python. Explain why one is recursive and the other is iterative.

A Level Computing#BristolMet Key Words

A Level Computing#BristolMet KEYWORDS EXPLAINED Sub routines are sections of code which perform a specific task which can be separated from the main program. They are called either procedures or functions. A function performs a specific task and returns a single value i.e input 1 add input 2, output answer A procedure performs a task or operation but does not return a value i.e print file or open file Parameters – when a function or procedure is defined information about the data item(s) being supplied are given. This is known as the parameters are usually expressed in (brackets) after the identifier.

A Level Computing#BristolMet PARAMETERS Parameters are needed to tell the computer what data types are being used for each variable in the subroutine, and in the case of functions, the data type of the ‘return value’ (the single value returned after the instructions have been carried out). What do these tell us? PROCEDURE Print Details (Name: String, Copies: Integer) FUNCTION Interest(AMT:Currency, Rate:Real, Yrs:Integer):Currency The function name is interest Amt of data type currency Rate of data type Real Yrs of data type Integer The return value of the function is of data type Currency The Procedure name is Print Details The parameter Name is of data type String The parameter Copies is of Integer

A Level Computing#BristolMet FUNCTIONS Functions need to be defined before they can be called (or used) in the main body of the program. In Python def function(): instructions… is the method for defining the function and it can be called again later in the program with a simple function() TASK: Look at the addcalc.py example and then apply to your multicalc.py TASK 2: Compare your original program with the functional version and discuss which you think is the more efficient. Prepare to answer the questions of when or why should you use functions in your program design.

A Level Computing#BristolMet RECURSION This is when a subroutine (procedure or function) calls itself. The subroutine executes instructions as normal until it calls itself, the subroutine then pauses and it goes through the process again until the conditions set out in the recursive subroutine are met – this is known as the stopping condition. So in a recursive subroutine it is also iterative in nature in the sense that it repeats itself until the stopping condition is met. See the example on p83-84 for further explanation and create a table of strengths/weakness of iteration vs recursion (p.85) Now answer the exam style questions on p85-86 (Complete for Hwk)