students = ["mary", "jane"] students.append("john") for name in students : print ("name is ", name) print("all done") #-------- def printNameList() : for name in students : print ("name is ", name) students = ["mary", "jane"] students.append("john") printNameList() print("all done") #---------------- def printNameList() : for name in students : print ("name is ", name) students = ["mary", "jane"] students.append("john") printNameList() teachers = ["gil", "margaret"] print("teachers:") printNameList() #doesn't work- prints the students again print("all done") #-------------------------- #ugly way - repeats almost same code. # no advantage doing this def printNameList() : for name in students : print ("name is ", name) def printNameList2() : for name in teachers : print ("name is ", name) students = ["mary", "jane"] students.append("john") printNameList() teachers = ["gil", "margaret"] print("teachers:") printNameList2() print("all done") #-------------------------- #parameterising the module # making it more general,more useful, more flexible def printNameList(namelist) : for name in namelist : print ("name is ", name) students = ["mary", "jane"] students.append("john") printNameList(students) teachers = ["gil", "margaret"] print("teachers:") printNameList(teachers) print("all done") # add to this program: list of colleges # do it again with lists of numbers: primes numbers, even numbers, multiples of 7