CECS 174 Lecture 4: Functions

54 views9 pages

Document Summary

# a function is a piece of code with three things: A return value (optional) computed based on the parameters. # the def keyword defines a function. def absolute_value(num): Based on the name, we can surmise that it is supposed to. # calculate the absolute value of a number. # inside a def is a block like any other. # a function"s purpose is to compute an answer. # is ready, we return it, sending it back to the person who wanted. # the answer. if num < 0: return -num. # a return statement causes the function to terminate. # that would normally follow the statement is skipped, and we go. # back to the line of code that called the function. else: return num. # the actual value given to a function to use as a parameter is called. # an argument. (we have learned this before. )

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents