Search code examples
pythonproject

display asterisk hockey stick


I'm sure this is an easy solution, but there are some details in this I am missing, which is not surprising considering this is my first programming class. I am having trouble getting this function to come out correctly, the instructions I have are as follows. """ Instructions: Your project will be implementing a number of functions. Each function displays a different shape. Your code MUST only use the following functions that are found in the project code to display anything to the console. (You may NOT use print statements in the functions you are completing.) star() displays a '*' character without the new line fill() displays a '#' character without the new line space() displays a ' ' character without the new line newline() displays a new line Each function is called in the main code found at the bottom of this project file. Functions contain the sample output that you need to match. """ # ========================================================================= # The next four function should not be changed. They should be used in the # functions that you complete. # =========================================================================

def star():
    """ Display a star without the normal new line """
    print('*', end='')

def fill():
    """ Display a fill character without the normal new line """
    print('#', end='')

def space():
    """ Display a space without the normal new line """
    print(' ', end='')

def newline():
    """ Display a new line """
    print()

def displayTriangle(n):
    for row in range(1, n + 1):
        for col in range(row):
            star()
        newline()
    newline()

def hockeyStick(handleLen, bladeLen):
    """ Display a hockey stick where the handle is of length handleLen
        and the blade is of length bladeLen.
        - This example has handleLen = 6, bladeLen = 7
    *
     *            
      *
       *
        *
         *
          *******
    """
    print('Hockey stick of size', handleLen, 'and', bladeLen)

the hockey stick pattern output should be able to be formatted to whatever is in the "handleLen" and "bladeLen". I have been trying to use triangles composed of spaces and adding an asterisk at the end but I can't get anything to work with the "handleLen" and "bladeLen". Any help is appreciated.


Solution

  • def hockeyStick(handleLen, bladeLen):
        """ Display a hockey stick where the handle is of length handleLen
            and the blade is of length bladeLen.
            - This example has handleLen = 6, bladeLen = 7
        *
         *            
          *
           *
            *
             *
              *******
        """
        print('Hockey stick of size', handleLen, 'and', bladeLen)
    
        for row in range(1, handleLen + 1):
            for col in range(row-1):
                space()
            star()
            newline()
    
        for col in range(handleLen):
            space()
        for col in range(bladeLen):
            star()