



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This is introductory course for computer science. Its about basic concepts involving in computer programming, structure and working. Key points in this lecture handout are: Functions, Dealing with Complexity, Controlling Complexity, Black Box Abstraction, Programming and Computer Science, Function Header, Function Body, Type of a Function
Typology: Study notes
1 / 7
This page cannot be seen from the preview
Don't miss anything!




Today ...
Homework
Many problems in programming arrise when building large systems
A function creates a named black box out of sequence of statements
In python we use the def keyword to define a function def print_message_twice(): msg = "Hello World!" print(msg) print(msg)
Once defined, functions can be called by name
print_message_twice() Hello World! Hello World!
In a script, the function must be delcared before it is used
We can also obtain the type of a function
type(print_circle_area) <class ’function’>
Many functions take arguments
Inside the function, arguments are assigned to parameters
A simple example of a function definition
def print_message_twice(msg): print(msg) print(msg)
To call the function, we pass in an argument
print_message_twice("Hello World!") Hello World! Hello World!
Functions must be delcared before called
print_message_twice("spam")
def print_message_twice(msg): print(msg) print(msg)
Unless the call is in the body of a function
def print_messages_twice(msg): print_message_twice(msg) print_message_twice(msg)
def print_message_twice(msg): print(msg) print(msg)
print_messages_twice("spam")