I keep getting indention errors in the while loop with the break. I checked out the existing thread on this issue, but the solution offered did not help me. Thank you! def rgb_hex(): invalid_msg = "Sorry, an error occured! Please check your input." red = int(raw_input("Enter red (R) value: ")) if (red < 0 or red > 255): print invalid_msg return green = int(raw_input("Enter green (G) value: ")) if (green < 0 or green > 255): print invalid_msg return blue = int(raw_input("Enter blue (B) value: ")) if (blue < 0 or blue > 255): print invalid_msg return val = (red << 16) + (green << 8) + blue print "%s" % (hex(val)[2:]).upper() def hex_rgb(): hex_val = raw_input("Enter the color (six hexadecimal digits): ") if len(hex_val) != 6: print "Invalid hexidecimal value. Try again." return else: hex_val = int(hex_val, 16) two_hex_digits = 2**8 blue = hex_val % two_hex_digits hex_val = hex_val >> 8 green = hex_val = two_hex_digits hex_val = hex_val >> 8 red = hex_val = two_hex_digits print "Red: %s Green: %s Blue: %s" % (red, green, blue) def convert(): while True: option = raw_input("Enter 1 to convert RGB to HEX. Enter 2 to convert HEX to RGB. Enter X to Exit: ") if option == '1': print "RGB to Hex..." rgb_hex() elif option == '2': print "Hex to RGB..." hex_rgb() elif option == 'X' or option == 'x': break else: print "An error occured. Please check your input." convert()
Hi @ryanbr ,
Check the indentation throughout your program.
Most of the improper indentation is within the
convert function, where statements that should be within
else blocks are not indented in comparison to the block headers.
Earlier within the program there are other statements that should be part of the
rgb_hex function that need similar attention, such as these ...
val = (red << 16) + (green << 8) + blue print "%s" % (hex(val)[2:]).upper()
It appears that at the beginning of the program you have chosen to use two spaces for each level of indentation. However, in other places later on, you have used tabs for indentation. Instead, choose a single technique, and use it consistently throughout the program.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.