Exam #1 You will have exactly 30 Mins to complete the exam.

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 4 Modular Programming with Functions.
Advertisements

Introduction to C Programming
Modular Programming With Functions
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
CS 106 Introduction to Computer Science I 02 / 27 / 2008 Instructor: Michael Eckmann.
Introduction to Methods
Lecture 5: Modular Programming (functions – part 1 BJ Furman 27FEB2012.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 6 Value-Returning.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Functions.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 3 Simple.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Oct 15, 2007Sprenkle - CS1111 Objectives Creating your own functions.
Functions, Procedures, and Abstraction Dr. José M. Reyes Álamo.
Procedural Programming Criteria: P2 Task: 1.2 Thomas Jazwinski.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
KIC/Computer Programming & Problem Solving 1.  Introduction  Program Modules in C  Math Library Functions  Functions  Function Definitions  Function.
Python Functions : chapter 3
FUNCTIONS. Topics Introduction to Functions Defining and Calling a Void Function Designing a Program to Use Functions Local Variables Passing Arguments.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Introduction to simple functions.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
Introduction to Functions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Loops and Simple Functions COSC Review: While Loops Typically used when the number of times the loop will execute is indefinite Typically used when.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
Lesson 06: Functions Class Participation: Class Chat:
Chapter 9: Value-Returning Functions
Topics Introduction to Functions Defining and Calling a Void Function
Lesson 08: Files Class Participation: Class Chat: Attendance Code 
Lesson 10: Dictionaries Topic: Introduction to Programming, Zybook Ch 9, P4E Ch 9. Slides on website.
Lesson 04: Conditionals Topic: Introduction to Programming, Zybook Ch 3, P4E Ch 3. Slides on website.
IST256 : Applications Programming for Information Systems
Lesson 05: Iterations Class Chat: Attendance: Participation
Topic: Functions – Part 2
JavaScript: Functions
Lesson 07: Strings Topic: Introduction to Programming, Zybook Ch 6, P4E Ch 6. Slides on website.
Function There are two types of Function User Defined Function
Functions CIS 40 – Introduction to Programming in Python
Functions.
Chapter 5 - Functions Outline 5.1 Introduction
Chapter 5 - Functions Outline 5.1 Introduction
Chapter 5 - Functions Outline 5.1 Introduction
Chapter 3 Simple Functions
Lesson 05: Iterations Topic: Introduction to Programming, Zybook Ch 4, P4E Ch 5. Slides on website.
Functions, Procedures, and Abstraction
Chapter 6 - Functions Outline 5.1 Introduction
Lesson 08: Files Topic: Introduction to Programming, Zybook Ch 7, P4E Ch 7. Slides on website.
Programming In Lesson 3.
Lesson 09: Lists Topic: Introduction to Programming, Zybook Ch 8, P4E Ch 8. Slides on website.
Lesson 06: Functions Class Chat: Attendance: Participation
Variables and Expressions
Lesson 09: Lists Class Chat: Attendance: Participation
5. Functions Rocky K. C. Chang 30 October 2018
Topics Introduction to Functions Defining and Calling a Void Function
Functions Christopher Harrison | Content Developer
Lesson 10: Dictionaries Class Chat: Attendance: Participation
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Introduction to Value-Returning Functions: Generating Random Numbers
Topics Introduction to Functions Defining and Calling a Function
IPC144 Introduction to Programming Using C Week 4 – Lesson 1
Loops and Simple Functions
Methods/Functions.
IST256 : Applications Programming for Information Systems
Functions Taken from notes by Dr. Neil Moore & Dr. Debby Keen
CPS125.
Functions, Procedures, and Abstraction
 A function is a named sequence of statement(s) that performs a computation. It contains  line of code(s) that are executed sequentially from top.
Using Modules.
Presentation transcript:

Exam #1 You will have exactly 30 Mins to complete the exam. Once you start you MUST finish When 30 mins is up, exam auto-submits, you will not receive points for un-answered questions. To begin enter the password: x64f7S6w

Lesson 06: Functions Topic: Introduction to Programming, Zybook Ch 5, P4E Ch 4. Slides on website. For Fun: http://www.informationisbeautiful.net/visualizations/million- lines-of-code/

Agenda EXAM #1: x64f7S6w Using import for functions from a module. How to inspect module contents and get help on functions. User-defined functions: arguments, named arguments, return values How to modularize our code with user-defined functions. You’ve Read: Zybook Ch 5 P4E Ch 4

Connect Activity The act of invoking a function is known as a: run call definition parameter

Functions A Function is a named sequence of statements which accomplish a task. They promote modularity, making our code less complex, easier to understand and encourage code-reuse. When you “run” a defined function it’s known as a function call. Functions are designed to be written once, but called many times. We've seen functions before: input("Enter Name: ") random.randint(1,10) int("9")

Functions, continued Functions are like their own little programs. They take input, which we call the function arguments (or parameters) and give us back output that we refer to as return values. x = input("Enter Name: ") y = random.randint(1,10) z = int("9") Arguments Function Return Value

Check Yourself: Functions Match the concept to its object name in the example. x = y(z) Function Name? Argument? Return Value? x y z

Functions & Python Modules Python modules are separate files of Python functions. In an object-oriented context functions are called Methods. When you import a module, Python executes the and all the variables and methods/ functions module become available to your program. The dir() function will display the names defined by the module. You can get help() on any function name to see how to use it.

Built in Modules vs. External The Python language has several modules which are included with the base language: Python Standard Library https://docs.python.org/3/library/ In addition you can import other libraries found on the Internet. More on this in a few weeks.

Watch Me Code 1 Import Modules: Import sys, math and random dir() help() Short and sweet demo

User-Defined Functions We can create out own functions with the def statement. Functions should return a value. def function-name(arguments): statements-in-function return expression

Help them Code 2: See student chooser Area and Perimeter of a rectangle. Functions make code readable Concept: Named Arguments Introduce named arguments.

Function Variable Scope Variables defined outside any function are Global Variables. These are accessible from everywhere including inside function definitions. Variables defined inside a function are Local Variables, and are only accessible inside the function definition. Local variables with the same name take precedence over global variables Best Practice: Avoid Global Variable Use In Functions!!!

Watch Me Code 3 Area and Perimeter of a rectangle. Understanding global variables Avoid their use in functions, use arguments instead. Introduce named arguments.

Check Yourself: Understanding Scope What is the value of the variable a as printed on line 7?

End-To-End Example: See the student chooser Temperature Conversions as functions Two functions f2c and c2f: Write program similar to a previous homework

In Class Coding Lab: The goals of this lab are to help you to understand: How to use Python's built-in functions in the standard library. How to write user-defined functions The benefits of user-defined functions to code reuse and simplicity. How to create a program to use functions to solve a complex idea