## Lecture 3 - Functions ## # Michelle Szucs # To download as a Python file, right-click the link # and select "Save link as..." # Modified from Lecture 2: def getAges(): # This function doesn't take any arguments myAge = int(raw_input("What is your age? ")) friendAge = int(raw_input("What is your friend's age? ")) # We want to return both values, so we're going to # put them in a tuple. # Note: The parentheses aren't necessary - # return myAge, friendAge would also work, # but I wanted to emphasize that it's a tuple. return (myAge, friendAge) ########## Lecture 3 Code ############ def getBirthYear(age): # This print statement will execute because it's # before the return statement print 75 return 2013 - age # This print statement WON'T execute because it's # after the return statement print 50 # This function is for you to use to understand the # difference between print and return def printBirthYear(age): print 2013 - age # Remember that since I don't have a return statement, # Python inserts an implicit return None # This next line is called "unpacking the tuple" - # we're assigning the values contained in the tuple # returned by getAges() to two seperate variables myAge, friendAge = getAges() birthYear = getBirthYear(myAge) friendBirthYear = getBirthYear(friendAge) print "In 2050 you'll be", 2050 - birthYear print "Your friend was born in", friendBirthYear