Lecture 4 Functions. 2 CodeCademy 4.a. 3 CodeCademy: comments.  As parameter of a function  Second way to introduce variables:  What do max, min,

Slides:



Advertisements
Similar presentations
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Advertisements

Lilian Blot CORE ELEMENTS SELECTION & FUNCTIONS Lecture 3 Autumn 2014 TPOP 1.
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
Python Mini-Course University of Oklahoma Department of Psychology Day 4 – Lesson 15 Tuples 5/02/09 Python Mini-Course: Day 4 – Lesson 15 1.
Week 8 Arrays Part 2 String & Pointer
Course A201: Introduction to Programming 11/11/2010.
1 Javascrbipt Intro Javascript (or js) is a programming language. Interpreted, not compiled. Not the same as java, but, similar. Use tags to use. Object-oriented.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Topic R3 – Review for the Final Exam. CISC 105 – Review for the Final Exam Exam Date & Time and Exam Format The final exam is 120-minutes, closed- book,
Chapter 2 Writing Simple Programs
2006 Fall MATH 100 Lecture 81 MATH 100 Lecture 25 Final review Class 25 Final review 1.Function of two or more variables.
Intro to Robots Conditionals and Recursion. Intro to Robots Modulus Two integer division operators - / and %. When dividing an integer by an integer we.
CS1022 Computer Programming & Principles
Python.
Programming for Linguists An Introduction to Python 24/11/2011.
Handling Lists F. Duveau 16/12/11 Chapter 9.2. Objectives of the session: Tools: Everything will be done with the Python interpreter in the Terminal Learning.
Python Mini-Course University of Oklahoma Department of Psychology Day 2 – Lesson 9 Iteration: Recursion 5/02/09 Python Mini-Course: Day 3 - Lesson 9 1.
Course A201: Introduction to Programming 11/04/2010.
Goals Approach Evaluation Intro to Python The two on-line sources Getting started with LPTHW.
By the end of this session you should be able to...
PHP - Basic Language Constructs CSCI 297 Scripting Languages - Day Two.
CompSci 101 Introduction to Computer Science September 23, 2014 Prof. Rodger.
Chapter 8 More On Functions. "The Practice of Computing Using Python", Punch & Enbody, Copyright © 2013 Pearson Education, Inc. First cut, scope.
Functions. Built-in functions You’ve used several functions already >>> len("ATGGTCA")‏ 7 >>> abs(-6)‏ 6 >>> float("3.1415")‏ >>>
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Introduction to Computing Using Python for loop / def- ining a new function  Execution control structures ( if, for, function call)  def -ining a new.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
9/14/2015BCHB Edwards Introduction to Python BCHB Lecture 4.
February ,  2/16: Exam 1 Makeup Papers Available  2/20: Exam 2 Review Sheet Available in Lecture  2/27: Lab 2 due by 11:59:59pm  3/2:
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
Beginning Fortran Introduction 13 October 2009 *Black text on white background provided for easy printing.
Midterm Review Important control structures Functions Loops Conditionals Important things to review Binary Boolean operators (and, or, not) Libraries (import.
Xi Wang Yang Zhang. 1. Easy to learn 2. Clean and readable codes 3. A lot of useful packages, especially for web scraping and text mining 4. Growing popularity.
 Run my CodeCademy and review the assignments.  The difference is left implicit. Try:  Float1 = isinstance( 2.2, float)  Float2 = isinstance( 2.,
2-2 The Distributive Property Distributive Property of Multiplication over Addition : Ex. 3(2+6) Multiplication Addition You can distribute a factor to.
Lecture 2 What is a computational problem? What is an instance of a problem? What is an algorithm? How to guarantee that an algorithm is correct? What.
4 March 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
CMPT 120 Topic: Searching – Part 2 and Intro to Time Complexity (Algorithm Analysis)
Indentations makes the scope/block Function definition def print_message (): print “hello” Function usages print_message () hubo.move ()// hubo is a class.
CompSci 101 Introduction to Computer Science February 5, 2015 Prof. Rodger Lecture given by Elizabeth Dowd compsci101 spring151.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
Python Basics.
Chapter 2 Writing Simple Programs
Discussion 4 eecs 183 Hannah Westra.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Based on slides by Shawn.
CS1022 Computer Programming & Principles
My Picture Dictionary Comments and Future Considerations: Sentences T
Fundamentals of Programming I Managing the Namespace
Turing Machine
String operations; More on function definitions; Conditional execution
CHAPTER 8 (skip , ) CHAPTER 10
Logical Operators and While Loops
Important Concepts from Clojure
Important Concepts from Clojure
Arithmetic operations, decisions and looping
CISC101 Reminders Slides have changed from those posted last night…
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
CISC101 Reminders Assn 3 due tomorrow, 7pm.
CSC1018F: Intermediate Python
Introduction to Python
Logical Operators and While Loops
Important Concepts from Clojure
Python Basics with Jupyter Notebook
The structure of programming
CISC101 Reminders Assignment 3 due today.
def-ining a function A function as an execution control structure
The return Statement © 2018 Kris Jordan.
Presentation transcript:

Lecture 4 Functions

2 CodeCademy 4.a.

3 CodeCademy: comments.  As parameter of a function  Second way to introduce variables:  What do max, min, abs do on text strings?  What if you switch the order of a print and return at the end of a function definition?

4  Careful: 18 refers to (* args), but we met this before  Ex. 19: different ways to call functions  Ex. 21: watch the order of evaluation ! LPTHW: 18, 19 and 21

6 Recursive functions: def countdown(n): if n > 0: print "I'm counting down, now at %d." % n countdown(n-1) elif n == 0: print "Happy New Year!" countdown(5)countdown(10)

7 And countup: def countup(n): if n > 0: countup(n-1) countup(n-1) print "I'm counting down, now at %d." % n print "I'm counting down, now at %d." % n elif n == 0: print "Happy New Year!" countup(5)countdown(10) Weird !!!

8 And infinitecount: def infinitecount(n): print "I'm still %d !" % n infinitecount(n)infinitecount(10)

9 Turing complete programming languages.  Allow to compute _any_ computable function.  comparison (==, !=,, =)  + Math (+, -, *, /)  + If  + functions  Are Turing complete.  Anything that can be done with “for”- or “while”- loops, can also be done with recursion.

10 Assignment for next week:  CodeCademy 5.a Lists and Dictionaries (31 min), 5.b A day at the supermarket (28 mins):  LPTHW Ex.32 (9 min), Ex. 34 (11 min)  Ignore all the long comments on ordinals/cardinals.