Nate Brunelle Today: Functions

Slides:



Advertisements
Similar presentations
Def f(n): if (n == 0): return else: print(“*”) return f(n-1) f(3)
Advertisements

Chapter 7: User-Defined Functions II
Q and A for Chapter 3.4 – 3.14 CS 104 Victor Norman.
1 Gentle Introduction to Programming Session 2: Functions.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 4- 1.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Subroutines Just like C, PERL offers the ability to use subroutines for all the same reasons – Code that you will use over and over again – Breaking large.
Introduction to Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Munster Programming Training
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 05.
Functions, Procedures, and Abstraction Dr. José M. Reyes Álamo.
Python Mini-Course University of Oklahoma Department of Psychology Day 2 – Lesson 5 Function Interfaces 4/18/09 Python Mini-Course: Day 2 - Lesson 5 1.
Announcements Project1 Due Wednesday September 21 st 4:30pm We will post instructions on how to turnin from home Note: you can always turn in from the.
Functions Chapter 4 Python for Informatics: Exploring Information
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Python Functions.
Introduction to Computing Using Python for loop / def- ining a new function  Execution control structures ( if, for, function call)  def -ining a new.
Chapter Making Decisions 4. Relational Operators 4.1.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 4 Making Decisions.
Functions Victor Norman CS104 Calvin College. Reading Quiz Counts toward your grade.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
More on Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Building java programs, chapter 3 Parameters, Methods and Objects.
Printing in Python. Printing Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external.
Introduction to Functions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
PHP Reusing Code and Writing Functions 1. Function = a self-contained module of code that: Declares a calling interface – prototype! Performs some task.
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)
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
More on Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
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.
CSC 1010 Programming for All Lecture 5 Functions Some material based on material from Marty Stepp, Instructor, University of Washington.
Functions Input and output Lecture 2. Constants #define – is a preprocessor directive Most common use.
CS0004: Introduction to Programming
Introduction to Python
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Python - Functions.
Instructor: Ioannis A. Vetsikas
CMSC201 Computer Science I for Majors Lecture 10 – Functions (cont)
© 2016 Pearson Education, Inc.,Hoboken, NJ. All rights reserved.
Teaching London Computing
Functions, Procedures, and Abstraction
Nate Brunelle Today: PyCharm
First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
CISC101 Reminders Assn 3 due tomorrow, 7pm.
Example 1.
Nate Brunelle Today: Functions again, Scope
Selection Statements.
Nate Brunelle Today: Turtles
Nate Brunelle Today: Conditional Decision Statements
CS150 Introduction to Computer Science 1
Python for Informatics: Exploring Information
G. Pullaiah College of Engineering and Technology
Nate Brunelle Today: Functions
Nate Brunelle Today: Strings, Type Casting
Nate Brunelle Today: Values and Types
Nate Brunelle Today: Conditional Decision Statements
Nate Brunelle Today: Conditional Decision Statements
Simplifying Rational Expressions
CISC101 Reminders Assignment 3 due today.
Nate Brunelle Today: Strings, Type Casting
Nate Brunelle Today: Functions again, Scope
CS 1111 Introduction to Programming Spring 2019
Functions Taken from notes by Dr. Neil Moore & Dr. Debby Keen
def-ining a function A function as an execution control structure
Functions, Procedures, and Abstraction
Nate Brunelle Today: Pseudo-Code
Functions John R. Woodward.
Scope Rules.
Presentation transcript:

Nate Brunelle Today: Functions CS1110 Nate Brunelle Today: Functions

CS Majors Night What’s it like to be a CS major? How do I declare a CS major? Find out Tonight! Rice 130 5pm

Questions?

Last Time Strings, casting types

Function Like going to chipotle: Enter with Your chipotle order in mind Input Instructions for how to turn your order into a burrito Things can happen at chipotle that leave chipotle Side effects E.g. less money in your bank account Leave with your burrito/bowl output

Creating a function def name(“stuff we need to do the function”): Indent Things we are doing return result

Functions Vocab Expression – Code that can become a value Literal expression – an expression that cannot be simplified Evaluate – turn an expression into a value Argument – value/expression we send into a function Parameter – name we use for input within a function definition Attached to an argument when we use the function Call/invoke – Use a function Return – exit the function with a value Return Value – the value we returned Side Effect – things that a function does beyond returning something

Advice on functions You usually don’t want functions with side effects Don’t use print, instead return a str Don’t use input, instead use parameters Good names Usually an action phrase Use docstrings Define function in one file, use in another

Scope Scope- The are where a variable has meaning Usually: variable is in scope when it is created onward. Functions: variable is in scope when it is created until end of the function definition