Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Stressful Subject by LeonidPK
def is_stressful(subj):
"""
recoognise stressful subject
"""
# condition of ALL UPPERCASE
if subj.isupper():
return True
# condition of '!!!' at the end of subject
if subj[-3:] == '!!!':
return True
# remove '!', '-' and '.'
subj_cleaned = ''.join(ch for ch in subj if ch not in '!-.')
# convert to lowercase
subj_cleaned = subj_cleaned.lower()
# add a space at the end of string (in case the first and the last characters of string are same)
subj_cleaned += ' '
# remove duplicate characters
subj_cleaned = ''.join([ch for i, ch in enumerate(subj_cleaned) if ch != subj_cleaned[i-1]])
#print(subj_cleaned)
red_words = ["help", "asap", "urgent"]
# check "red" words condition
if any(word in subj_cleaned for word in red_words):
return True
return False
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert is_stressful("Hi") == False, "First"
assert is_stressful("Hi!!!") == True, "!!!"
assert is_stressful("H! H! H!") == True, "H! H! H!"
assert is_stressful("H! a! H!") == False, "H! a! H!"
assert is_stressful("H!e!L!P!") == True, "H!E!L!P!"
assert is_stressful("I need! help .!") == True, "HELP"
assert is_stressful("UUUURGGGEEEEENT ") == True, "UUUURGGGEEEEENT "
assert is_stressful("I neeed HELP") == True, "Second"
print('Done! Go Check it!')
March 17, 2019
Comments: