CMU Coding Bootcamp

feat: sep30 level 4

thecoded.prof fc07492c a4535742

verified
Changed files
+18
python
assignments
sep30
+18
python/assignments/sep30/level4/blendColors.py
··· 1 + def halfway(a: int, b: int) -> int: 2 + return 0 3 + 4 + def blendColors(rgb1: int, rgb2: int): 5 + (r1,g1,b1) = [int(str(rgb1).zfill(9)[i:i+3]) for i in range(0,9,3)] 6 + (r2,g2,b2) = [int(str(rgb2).zfill(9)[i:i+3]) for i in range(0,9,3)] 7 + (r3,g3,b3) = [round((r1+r2)/2), round((g1+g2)/2), round((b1+b2)/2)] 8 + (final_r, final_g, final_b) = [str(x).zfill(3) for x in (r3,g3,b3)] 9 + final_color = int(final_r + final_g + final_b) 10 + return final_color 11 + 12 + print('Testing blendColors()...', end='') 13 + assert(blendColors(204153050, 104000152) == 154076101) 14 + assert(blendColors(220153102, 151189051) == 186171076) 15 + assert(blendColors(153051153, 51204) == 76051178) 16 + assert(blendColors(123456789, 123456789) == 123456789) 17 + assert(blendColors(0, 0) == 0) 18 + print('Passed!')