Presentation is loading. Please wait.

Presentation is loading. Please wait.

IST256 : Applications Programming for Information Systems

Similar presentations


Presentation on theme: "IST256 : Applications Programming for Information Systems"— Presentation transcript:

1 IST256 : Applications Programming for Information Systems
Functions

2 Agenda Connection Activity Teaching: Practice Activity
Quiz 2, Homework Check Teaching: Functions, definitions, calls, named arguments, variable scope Practice Activity Name-Here

3 Quiz #2, HW Check Connect Activity After you turn in the quiz,
Open number guessing game For a Homework Check

4 Functions A Functions are a named sequence of statements which accomplish a task. They promote modularity, making our code less complex 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. Functions are like their own little programs. They take input, which we call the function arguments and give us back output that we refer to as return values. Arguments Function Return Values

5 Watch Me Code “I know a guy, his name is Terry” “Hey Lade, Lade, Lo!” “He got so hungry, he ate is canary” “99 Bottles of Beer on the wall” # this does not execute until called def chorus(): return "Hey Lade, Lade, Lo" # start of program print ("I know I guy his name is Terry") print (chorus()) print ("He got so hungry he ate his canary")

6 Check Yourself: 90 Second Challenge
What is x(1,1,1) ? What is x(100,0,-100)? What is x(‘1’,’2’,’3’)? What is the name of this function? How many inputs does it have? How many outputs?

7 Watch Me Code Area and Perimeter of a rectangle.
Concept: Named Arguments Introduce named arguments.

8 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

9 Check Yourself: 90 Second Challenge
List the Global Variables List the variables local to x() What prints on line 7? Line 8? Line 9? Is the variable a on lines 2 and 6 the same? Explain.

10 Help me Code Grade Calculator:
Write a function to calculate a letter grade given a number grade based on this scale: >=90  A | >=80  B | >=70  C |Else  F Then write a program to input a number grade and output a letter grade.

11 Now You Code Write a function to convert miles to KM and write another function to convert KM to miles. Test your functions by writing a program: It should input a distance value as a float and input a unit (either KM or Miles) It then outputs the converted value. If you enter miles, it converts to KM, for example. It should repeat this process until a ZERO is entered for a unit.


Download ppt "IST256 : Applications Programming for Information Systems"

Similar presentations


Ads by Google