8(iii)
Write a Python program that performs the following operations on a string:
- (a)Create a string with the value "Artificial Intelligence".
- (b)Convert the entire string to uppercase and print the result.
- (c)Find and print the position of the substring "Intelligence" within the string.
- (d)Replace the substring "Artificial" with "Machine" and print the new string.
- (e)Check if the string starts with "Machine" and print the result (True/False).
- (f)Count and print the number of occurrences of the letter 'i' in the string.
Show SolutionHide Solution↓
original_string = "Artificial Intelligence"
uppercase_string = original_string.upper()
print("Uppercase string:", uppercase_string)
position = original_string.find("Intelligence")
print("Position of 'Intelligence':", position)
new_string = original_string.replace("Artificial", "Machine")
print("New string:", new_string)
starts_with_machine = new_string.startswith("Machine")
print("Starts with 'Machine':", starts_with_machine)
count_i = original_string.count('i')
print("Number of occurrences of 'i':", count_i)
Uppercase string: ARTIFICIAL INTELLIGENCE
Position of 'Intelligence': 11
New string: Machine Intelligence
Starts with 'Machine': True
Number of occurrences of 'i': 4