In the exercise below:
1. Create a variable sentence and assign a sentence of your choice to it.
2. Find and print the length of the sentence.
3. Convert the sentence to uppercase and print the result.
4. Replace a specific word in the sentence with another word.
5. Count and print the number of occurrences of a particular letter in
the sentence.
6. Create a new variable reversed_sentence and assign the reversed
version of the sentence to it.
7. Print the original sentence and the reversed sentence.
# 1. Create a variable 'sentence' and assign a new sentence to it
sentence = "Learning how to code opens up countless opportunities everywhere."
# 2. Find and print the length of the sentence
sentence_length = len(sentence)
print(f"Length of the sentence: {sentence_length} characters")
# 3. Convert the sentence to uppercase and print the result
uppercase_sentence = sentence.upper()
print(f"Uppercase sentence: {uppercase_sentence}")
# 4. Replace a specific word in the sentence with another word
new_sentence = sentence.replace("code", "program")
print(f"Updated sentence: {new_sentence}")
# 5. Count and print the number of occurrences of a particular letter in the sentence
letter_to_count = "e"
occurrences = sentence.count(letter_to_count)
print(f"Number of occurrences of '{letter_to_count}': {occurrences}")
# 6. Create a new variable 'reversed_sentence' and assign the reversed version of the sentence to it
reversed_sentence = sentence[::-1]
# 7. Print the original sentence and the reversed sentence
print(f"Original sentence: {sentence}")
print(f"Reversed sentence: {reversed_sentence}")
មតិយោបល់ 0