Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
2 solutions solution in Clear category for Bird Language by donnythelegend
VOWELS = "aeiouy"
def translation(phrase):
# Solution 1: Longer way using for loop and counter.
## Initialize empty string for translation.
#phrase_t = ''
## Initialize counter for values.
#vowel_count = 0
## Initialize null variable for temporary vowel storage.
#vowel_temp = None
## Loop through phrase.
#for c in phrase:
# # Check if c is not in VOWELS.
# if c not in VOWELS:
# # Concatenate c with phrase_t.
# phrase_t += c
# # Point vowel_count to 0.
# vowel_count = 0
# # Check if c is not the same as vowel_temp, or if vowel_count is 0.
# elif (c != vowel_temp) or (vowel_count==0):
# # Point vowel_count to 1.
# vowel_count = 1
# # Point vowel_temp to c.
# vowel_temp = c
# else:
# # If the above conditions aren't valid, then add to vowel_count.
# vowel_count += 1
# # Check if vowel_count is 3.
# if vowel_count==3:
# # Concatenate c with phrase_t.
# phrase_t += c
# # Point vowel_count back to 0.
# vowel_count = 0
## Return phrase_t.
#return phrase_t
# Solution 2: Shorter way using while loop and index.
# Initialize empty string for translation.
phrase_t = ''
# Initialize index value.
index = 0
# Iterate while index is valid within phrase.
while index < len(phrase):
# Concatenate the index character in phrase with phrase_t.
phrase_t += phrase[index]
# Check if the index character is in VOWELS.
if phrase[index] in VOWELS:
# Add 3 to index since important vowels come in sets of 3.
index += 3
# Otherwise, check if the index character is a whitespace.
elif phrase[index]==' ':
# Add 1 to index so that we can evaluate the next character.
index += 1
else:
# If the above conditions are invalid,
# the index character must be a consonant.
# Since an irrelevant vowel always occurs after consonants,
# we add 2 to index to skip it.
index += 2
# Return phrase_t.
return phrase_t
if __name__ == '__main__':
print("Example:")
print(translate("hieeelalaooo"))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert translation("hieeelalaooo") == "hello", "Hi!"
assert translation("hoooowe yyyooouuu duoooiiine") == "how you doin", "Joey?"
assert translation("aaa bo cy da eee fe") == "a b c d e f", "Alphabet"
assert translation("sooooso aaaaaaaaa") == "sos aaa", "Mayday, mayday"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
April 29, 2021
Comments: