CMU Coding Bootcamp
at main 591 B view raw
1def fullRGB(rgb: int) -> str: 2 """Left pad 0's to make the string of length 9.""" 3 return str(rgb).zfill(9) 4 5 6def isGray(rgb: int) -> bool: 7 """Return True if the RGB value passed is considered 'gray'.""" 8 rgbStr = fullRGB(rgb) 9 return (rgbStr[0:3] == rgbStr[3:6]) and (rgbStr[3:6] == rgbStr[6:9]) 10 11 12print("Testing isGray()...", end="") 13assert isGray(112112112) == True 14assert isGray(112112113) == False 15assert isGray(123195060) == False 16assert isGray(255255255) == True 17assert isGray(0) == True 18assert isGray(19019019) == True 19assert isGray(175112) == False 20print("Passed!")