def capitalize_or_join_words(sentence):
"""
If the given sentence starts with *, capitalizes the first and last letters of each word in the sentence,
and returns the sentence without *.
Else, joins all the words in the given sentence, separating them with a comma, and returns the result.
For example:
- If we call capitalize_or_join_words("*i love python"), we'll get "I LovE PythoN" in return.
- If we call capitalize_or_join_words("i love python"), we'll get "i,love,python" in return.
- If we call capitalize_or_join_words("i love python "), we'll get "i,love,python" in return.
Hint(s):
- The startswith() function checks whether a string starts with a particualr character
- The capitalize() function capitalizes the first letter of a string
- The upper() function converts all lowercase characters in a string to uppercase
- The join() function creates a single string from a list of multiple strings
"""
if (sentence.startswith('*')):
list_sentence = ','.split(sentence)
list_car = []
list_sentence.pop(0)
for i in range(0,len(list_sentence),1):
list_car = ','.split(list_sentence[i])
for i in range(0,len(list_car),1):
if (i == 0 or i == len(list_car[i])):
list_car[i].upper()
list_car = ''.join(list_car)
sac = ' '.join(list_sentence)
return sac
else:
sentence = ','.join(sentence)
return sentence