Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
ord() all day. solution in Clear category for Secret Message by tigercat2000
def find_message(text):
"""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.
return resolved
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