








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









^ Formal parameters only receive the
values
of the
actual parameters Assigning a new value to a formal parameter doesnot affect the actual parameter Python passes actual parameters
by value
^ Can functions in Python mutate parameters?
^ How do functions send information back?^ ^ Return statements^ ^ Mutating
parameters ^ Value of actual parameter must be a mutable object ^ State of the mutable object is changed ^ The actual parameter itself is NOT changed since it refers tothe same object ^ Parameter is still passed by value
^ Definite Loop^ ^ We know at the beginning of the loop how many times itsbody will execute^ ^ Implemented in Python as a
for^ loop.
^ Indefinite loop^ ^ The body executes as long as some condition is true.^ ^ Implemented in Python as a
while^ loop.
^ Can be an infinite loop if the condition never becomesFalse. Python's
for line in file:
construct
^ indefinite loop that looks syntactically like a definite loop!
^ Open module averageUserCount.py and execute ittogether ^ When does the loop terminate? ^ Is this the best way to make the user enter input?^ ^ Why?^ ^ Why not?
^ Open module averageMoreData.py and execute ittogether ^ User no longer has to count, but still has a bigburden
^ What if negative numbers are legitimate values? ^ Open module averageOtherSentinel.py and studythe code^ ^ Execute it together^ ^ What is the sentinel? ^ Again note:
sentinel value is not used in calculations.
^ Open module averageFile.py and execute togetherwith input file numbers.txt ^ Uses a
for^ loop as we have seen before
^ Also note the conditional execution of
main()
Define function
listAndMax()
in module
listMax.py
that
^ Prompts the user to enter numbers, one at a time ^ Uses a blank line (
main()
in module
listMax.py
that
^ Calls listAndMax() ^ Prints the list of numbers entered ^ Prints the maximum value of the list of numbers