Class 29 — March 30
It still functions
Riding together — Driving and navigating — Together as one
Look both ways
Agenda
- Functions that modify existing lists
- Pass by value parameter passing nuances
- Mindful collaboration
- Review solutions for last class
Outcomes
- Further appreciation for partnering
- Better able to convert problem specifications into working functions manipulating lists
- Better understanding of parameter passing
Module cautionary_tale_of_two_cities.py
- Consider function
f()
.
def f( x, y ) :
rmbr = x
x = y
y = rmbr
- What is the output of the following code fragment?
city1 = 'London'
city2 = 'Paris'
f( city1, city2 )
print( city1 )
print( city2 )
Module and_yet.py
- Consider function
g()
.
def g( strings, s ) :
n = len( strings )
for i in range( 0, n ) :
strings[ i ] = s
- What is the output of the following code fragment?
cities = [ 'Richmond', 'Blacksburg', 'Roanoke', 'Lynchburg', 'Norfolk' ]
g( cities, 'Cville' )
print( cities )
Statement
- We are going to do paired programming again. Although strongly encouraged, you are not required to do so.
- Please do not use the same partner if you already partnered with that person twice.
- All class members must fill out the evaluation form.
Problem set and set up
- Module aid — three functions that manipulate their list paramater(s)
- The only apps to be running on your laptops are a browser and PyCharm. The browser usage should be limited to CS 1112 materials.
- You must use my aid.py for this assignment.
- Do not access any past or outside code while working on this assignment.
- Review problem set description.
- Determine primary driver and navigator roles for each of the functions — both team members must have multiple experiences as driver and navigator.
- Determine driver and navigator machines and for problem set.
- On designated driver machine download and open aid.py and abet.py in PyCharm. Close all other program and module tabs.
After class
- Email partner copy of
aid.py
.
- Submit your evaluation form.
- Look over your artifacts.
- Take yet another look at function epistle
- Take another look at the Hands on Python Tutorial
- Try CodingBat – it’s batting practice for writing functions
Warning: fopen(/l/cs1112/public_html/defs/htm/181-trailer): Failed to open stream: No such file or directory in /l/cs1112/public_html/defs/php/read.php on line 5
Unable to open file!