''' Purpose: develop programmer-defined functions ''' # function voting_age(): returns how old you need to be to vote; i.e. the # integer 18. # the function should not print() anything, it should return 18 # you will never need to use input() in a function in this class def voting_age() : # this function does not have any parameters, so the parentheses are empty result = 18 return result # we are returning something called result, so we need to figure out what result is # any code in this function after the return statement will not be run # as soon as we reach a return statement, we exit the function and go back to the code that invoked it # function has_blanks( s ): returns a whether s contains at least one blank # character; i.e., returns True if s contains a blank, and returns # False otherwise. def has_blanks( s ) : # this function takes 1 string parameter, s # this function needs to return True or False every if ( " " in s ) : result = True else : result = False return result # function great_seal( ): prints the string 'E Pluribus Unum' def great_seal() : # no information needed, so no parameter # no result, so no return statement print( 'E Pluribus Unum' ) return # tell Python we're all done, and it will automatically return None # return statement is optional in functions that do not hand anything back to the user # function a_ing( n ) prints n lines of output. The first line prints a # single 'a', the second line prints 'aa', the third line prints 'aaa', # and so on. def a_ing( n ) : # this takes a single integer parameter, n # this does not return anything, it just prints # this function is going to assume that n is an integer, we do not need to cast it or clean it up in any way for i in range( 0, n ) : # i is a commonly used loop variable for counting # could also loop through the range( 1, n + 1 ) and output = 'a' * i # print i + 1 'a's per line output = 'a' * ( i + 1 ) print( output )