ord() all day. solution in Clear category for Secret Message by tigercat2000
"""Find a secret message"""
# Initialize the return value as an empty string. If there are no capital letters, it expects an empty string anyways.
resolved = ""
# Iterate over every character in the text with a for..in loop.
for c in text:
# This is where things get a little tricky.
# The ord() function takes a 1 length string and turns it into a decimal representation of the character code for that letter.
asc = ord(c)
# Normal english capital letters are in a specific range of character codes, which is the same for plain ASCII and unicode.
# So, check if the character code is between 64 (@) and 91 ([).
if 64 < asc < 91:
# If it is, add it to the final message.
resolved += c
# Return the final message.
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert find_message("How are you? Eh, ok. Low or Lower? Ohhh.") == "HELLO", "hello"
assert find_message("hello world!") == "", "Nothing"
assert find_message("HELLO WORLD!!!") == "HELLOWORLD", "Capitals"
Nov. 5, 2016