We think you have liked this presentation. If you wish to download it, please recommend it to your friends in any social system. Share buttons are a little bit lower. Thank you!
Presentation is loading. Please wait.
Published byIsabel Lamb
Modified about 1 year ago
ITEC 109 Lecture 15 Advanced functions
Functions (2) Review Functions –Parameters –Return statements –Variable scope
Functions (2) Objectives Functions calling other functions Patterns Examples
Functions (2) Easy Main to function and back def FunctionName(): printNow(“I am a function”) def FunctionTwo(): printNow(“I am the second”) FunctionName() FunctionTwo()
Functions (2) Driver Curve1 Curve2 Curve3
Functions (2) Pro/Con Pro –Breaks a problem into steps –Easy to re-order operations in the code Con –Initial setup cost is high –Requires design, can’t just code it ™
Functions (2) Application Standard cycle pattern Driver IO Compute Output def getValue1(): return 3; def getValue2(): return 5; def compute(a, b) return a+b; def ouput(value) printNow(value) x =getValue1(); y= getValue2(); result = compute(x,y); output(result);
Functions (2) Pro/Con Pro –Separates parts of implementation (keyboard vs file) –Scaling of project Con –Data management –Questions of what happens when you need to mix input / computation
Functions (2) Chooser Driver Input Function 2 Function3 Choice def getBalance(): return 55; def badCredit(): printNow(“Work harder”) def goodCredit(): printNow(“Keep it up”) amount = getBalance(); if (amount > 50): goodCredit(); else: badCredit();
Functions (2) Stair step Driver Function 2 Function3 Function 1 def function1(): function2(); def function2(): function3(); def function3(): printNow(“Complicated”) function1()
Functions (2) Pro/Con Pro –Models more complex problems Con –What happens when something goes wrong? –If A calls B, which calls C, which calls A, what happens?
Functions (2) Stair climbing Driver Function 2 Function3 Function 1 Start Go back up *Warning*
Functions (2) Example def sum4(): return 4 + sum3(); def sum3(): return 3 +sum2(); def sum2(): return 2 + sum1(); def sum1(): return 1; answer =sum4(); printNow(answer) //Prints out sum of
Functions (2) Pro/Con Pro –Crazy and semi-useful tool –Brain bending mental exercise Con –Algorithm design complexity –Debugging (100% CPU usage) –Recursion
Functions (2) Combinatio n Driver Function 1 Function 2 Choice Function3 What kind of code would we need for this?
Functions (2) Pro/Con Pro –Divide and conqueror –Flexibility Con –You have to figure it out –Requirements –Design –Implementation
Functions (2) Review Function review Functions calling functions Pattern review
Chapter 6 Writing a Program Bjarne Stroustrup
CMPT 120 Introduction To Computing Science And Programming I Pseudocode Summer 2012 Instructor: Hassan Khosravi.
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Python Programming Chapter 13: Classes and Functions Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
Sub Procedures and Functions. Procedures in VBA The main idea: encapsulate some code in its own procedure (There are two kinds: Sub Procedures and Functions)
Higher-Order Functions and Loops c. Kathi Fisler,
A Practical Guide To Unit Testing John E. Boal TestDrivenDeveloper.com.
1 Writing Pseudocode And Making a Flow Chart Instructor: Richard T. Vannoy II A Number Guessing Game.
Lecture 10 Methods COMP1681 / SE15 Introduction to Programming.
Credit hours: 4 Contact hours: 50 (30 Theory, 20 Lab) Prerequisite: TB143 Introduction to Personal Computers.
Chapter 4 Computation Bjarne Stroustrup
Gearing up for the stretch run CSCI 21, Spring 2013.
Md. Ahsan Arif, Assistant Professor, Dept. of CSE, AUB 1 Algorithm Analysis Dept. of CSE, AUB.
Chapter 7 Problem Solving and Algorithms. 2 Problem Solving How to Solve It: A New Aspect of Mathematical Method by George Polya "How to solve it list"
The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or.
Chapter 11 Introduction to Programming in C. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display C: A High-Level.
SCRATCH Lesson Two – Interactive Concepts Using Sensing, Operators, and Variables.
Defining Decision Support System The concept of a (DSS) is extremely broad and its definitions vary: It is "a computer-based system that aids the process.
1 l Basics of Recursion l Programming with Recursion Recursion.
Escape Sequences \nnewline \t tab \bbackspace \rcarriage return \single quote \double quote \\backslash.
Generating Ideas #1: Research Patterns Nick Feamster and Alex Gray College of Computing Georgia Institute of Technology.
EMS1EP Lecture 7 Program Structure and Serial I/O Dr. Robert Ross.
RAM (cont.) 2 20 bytes of RAM (1 Mega-byte) Write Address Data input Data Output 20 bits of address 8 bits (1 byte) of data.
Getting Input in Python Assumes assignment statement, typecasts.
Exam Preparation. How to Study You may notice after doing a few practice exams you still have a few learning gaps! Go back to fill those learning gaps.
More on Psuedo-Code Sangeetha Parthasarathy 1/23/01.
Case Study: A Recursive Descent Interpreter Implementation in C++ (Source Code Courtesy of Dr. Adam Drozdek) Payap University ICS220 - Data Structures.
Composite Functions. What Are They? Composite functions are functions that are formed from two functions f(x) and g(x) in which the output or result of.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 1: Introduction: Program Structure & Java Syntax.
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 5: Control Structures II (Repetition)
© 2016 SlidePlayer.com Inc. All rights reserved.