printf("#%x", (0x10000*red) | (0x100*green) | blue);
that's a great way to turn the values into the hex string, but you start out with a string, not just three integers
which I obviously didn't say explicitly
anyway, on a related note
if you know me, you know I love regular expressions (or maybe you don't know that whether you know me or not)
so I made one for RGB values
(?:rgba?)?\(?(\d{1,3}),?\s*(\d{1,3}),?\s*(\d{1,3})(?:,?\s*(\d{1,3}))?\)?question mark count: 10it will match all of the following:
244 55 66
244, 55, 66
244,55,66
(244, 55, 66)
rgb(244, 55 66)
rgba(244, 55,66, 0)
three groups, with the values 244, 55, and 66. optionally the alpha value may be there, and in the one where it is, it's 0
it's just a regular expression though, and it does not care one bit if you have a fourth value without having typed "rgba," nor if you type "rgba" with only three values
however if that first bit is present it
must be either "rgb" or "rgba" because while it would certainly be possible to allow you to leave some out, then it would look like
(?:r?g?b?a?)? and honestly who wants to see that many question marks??????
now that I think about it I also could've gone with something like
(?:[rgba]{1,4})? but then you'd be able to type junk like "rrrr(1, 2, 3)" and quite frankly I wouldn't stand for that
regex for hex codes would be a lot simpler
also bluetoothboy 2 things:
1. yours can only go from rgb to hex but what about the other way around
2. you should move on to python 3