Professional Documents
Culture Documents
1.4 (1-9 Writing Simple Functions)
1.4 (1-9 Writing Simple Functions)
1. Briefly explain the four main benefits of designing a program with functions.
4. What happens to the flow of execution when a function is called? What happens
when the end of the function’s block is reached?
A scope of a variable refers to the parts of the code that the variable
can be accessed from without errors including a function,module or
class
6. Is it permissible to use the same local variable name in two different functions?
Explain why or why not. Write an example program.
Yes,because the memory will erase the variable value after the
function is fully executed .So,having two local variables for two
different functions will not interfere with each other or change their
values.This due their different scopes so each function will have its
own version of the local variable.
def display_name():
name = "Johnny" #local variable 1
print(name)
def display_name2():
name = "Kozman" #local variable 2
print(name)
display_name()
display_name2()#there is no overlapping each function used
the name variable defined inside it
2 - Write a function called display_face() that prints a face, using text
characters, hopefully, better looking than this one:
/////
| o o |
(| ^ |)
| [_] |
=====
Add mainline logic (i.e., a main() function) to your program to demonstrate how to call
your function.
def main():
display_hair()
display_eyes()
display_nose()
display_smile()
display_end()
def display_hair():
print(" /c/c/c/c/ ")
def display_eyes():
print(" |-[o]-[o]-|")
def display_smile():
print(" | \-\_/-/ |")
def display_nose():
print("(| **** |)")
def display_end():
print("===========")
main()