Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Stressful Subject by aya.kanazawa
import re
def is_stressful(subj):
"""
recoognise stressful subject
"""
if re.match(r'.+!!!$', subj) or subj.isupper():
return True
for word in subj.split(" "):
only_alphabet = re.sub(r'[^a-z]', '', word.lower())
#print(only_alphabet)
for red_reg in [r'h+e+l+p+', 'a+s+a+p+', 'u+r+g+e+n+t']:
if re.match(red_reg, only_alphabet):
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("I neeed HELP") == True, "Second"
assert is_stressful("I neeed help") == True, "3rd"
assert is_stressful("I neeed H!E!L!P") == True, "4th"
assert is_stressful("I neeed HHHEEEEEEEEELLP") == True, "5th"
assert is_stressful("do it a.s.a.p") == True, "6rd"
assert is_stressful("URGENT") == True, "7th"
assert is_stressful("exclamation!!!") == True, "8th"
assert is_stressful("CAPITAL ONLY") == True, "9th"
print('Done! Go Check it!')
April 23, 2019