CMPT 120 Topic Where to put functions in

  • Slides: 8
Download presentation
CMPT 120 Topic: Where to put functions in a program

CMPT 120 Topic: Where to put functions in a program

Where to put functions in our Python program # Header Comment Block Header comment

Where to put functions in our Python program # Header Comment Block Header comment block + import statement(s) # Function 1 … # Function n Function definitions # Main part of my program The main part of my program 2

Function call –> situation 1 Python program # Header Comment Block # Function Header

Function call –> situation 1 Python program # Header Comment Block # Function Header comment block + import statement(s) Function definition # Main part of my program Function is called The main part of my program 3

Function call –> situation 2 Python program # Header Comment Block # Function 1

Function call –> situation 2 Python program # Header Comment Block # Function 1 # Function 2 # Main part of my program Function 1 is called Function 2 is called Header comment block + import statement(s) Function definitions The main part of my program 4

Function call –> situation 3 Python program # Header Comment Block # Function 1

Function call –> situation 3 Python program # Header Comment Block # Function 1 # Function 2 Header comment block + import statement(s) Function definitions Function 1 is called # Main part of my program Function 2 is called The main part of my program 5

Function call -> Would this situation work? Python program # Header Comment Block #

Function call -> Would this situation work? Python program # Header Comment Block # Function 1 # Main part of my program Function 1 is called Function 2 is called # Function 2 Header comment block + import statement(s) Function definition The main part of my program Function definition 6

Function call –> Would this situation work? Python program # Header Comment Block #

Function call –> Would this situation work? Python program # Header Comment Block # Function 1 Function 2 is called # Function 2 # Main part of my program Function 1 is called Header comment block + import statement(s) Function definitions The main part of my program 7

Where to put functions in our Python program – Not a good idea! Python

Where to put functions in our Python program – Not a good idea! Python program # Header Comment Block # Main part of my program Header comment block + import statement(s) The main part of my program # Function 1 # Function 2 Function definitions 8