= "natural language processing"
text
# Convert the string to uppercase
= text.upper()
uppercase_text
# Print the result
print(uppercase_text) # Output: NATURAL LANGUAGE PROCESSING
NATURAL LANGUAGE PROCESSING
Task: Change a given string to uppercase.
Instructions:
text
and assign it a string value (e.g., “natural language processing”)..upper()
method to convert the string to uppercase.Task: Count the number of vowels in a given string.
Instructions:
sentence
and assign it a string value (e.g., “I love Python programming”).vowel_count
to keep track of the number of vowels in the sentence.sentence = "I love Python programming"
# Initialize the vowel count
vowel_count = 0
# Define the set of vowels
vowels = "aeiouAEIOU"
# Loop through each character in the sentence
for char in sentence:
if char in vowels:
vowel_count += 1
# Print the total number of vowels
print("Number of vowels:", vowel_count) # Output: Number of vowels: 8
Number of vowels: 7
Task: Replace a word in a string with another word.
Instructions:
text
and assign it a string value (e.g., “NLP is fun”)..replace()
method to change the word “fun” to “awesome”.Task: Extract a substring from a given string.
Instructions:
text
and assign it a string value (e.g., “Natural Language Processing”).