''' Name: Email id: Purpose: develop programmer-defined functions ''' # function voting_age(): returns how old you need to be to vote; i.e. the # integer 18. # Function Writing: # def function_name(parameters): # function body def voting_age(): ''' Returns how old you need to be to vote in the US; i.e. the integer 18 ''' return 18 # 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 ): ''' returns a whether s contains at least one blank character; i.e., returns True if s contains a blank, and returns False otherwise. ''' blank = " " if ( blank in s ): # if (" " in s): # found a blank result = True else: # no blank result = False return result # result will be True or False # if s.count( blank ) > 0 works too! # function great_seal( ): prints the string 'E Pluribus Unum' def great_seal(): ''' prints the string 'E Pluribus Unum' ''' print( 'E Pluribus Unum' ) # but remember print is not the same as return! # 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 ): ''' 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. ''' # Accumulator current_output = '' # Initialize an empty string and gradually add an a to the accumulator for i in range( 0, n ): current_output = current_output + 'a' print( current_output ) # Alternate way - No Accumulator # for i in range(1,n+1): # a_s = 'a'*i # concatenates this many 'a's together # print(a_s) # You can have functions that explicitly return something or don't have an explicit return # statement! But all functions return something! # You can have functions with no parameters!