Skip to main content
Engineering LibreTexts

5.15: Reusing The Constant Variables

  • Page ID
    14545
  • def flashButtonAnimation(color, animationSpeed=50):
        if color == YELLOW:
            sound = BEEP1
            flashColor = BRIGHTYELLOW
            rectangle = YELLOWRECT
        elif color == BLUE:
            sound = BEEP2
            flashColor = BRIGHTBLUE
            rectangle = BLUERECT
        elif color == RED:
            sound = BEEP3
            flashColor = BRIGHTRED
            rectangle = REDRECT
        elif color == GREEN:
            sound = BEEP4
            flashColor = BRIGHTGREEN
            rectangle = GREENRECT
    

    Depending on which Color value is passed as an argument for the color parameter, the sound, color of the bright flash, and rectangular area of the flash will be different. Line 2 [151] to 17 [166] sets three local variables differently depending on the value in the color parameter: sound, flashColor, and rectangle