Robotics & Artificial Intelligence
Write a Python program that performs the following operations on a string:
- Create a string with the value "Artificial Intelligence".
- Convert the entire string to uppercase and print the result.
- Find and print the position of the substring "Intelligence" within the string.
- Replace the substring "Artificial" with "Machine" and print the new string.
- Check if the string starts with "Machine" and print the result (True/False).
- Count and print the number of occurrences of the letter 'i' in the string.
Python String Manipulation
1 Like
Answer
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)Output
Uppercase string: ARTIFICIAL INTELLIGENCE
Position of 'Intelligence': 11
New string: Machine Intelligence
Starts with 'Machine': True
Number of occurrences of 'i': 4
Answered By
3 Likes
Related Questions
Explain the importance of defining the problem statement in an AI project. How does it impact the project's success?
Write a Python program that performs the following operations on a tuple:
- Create a tuple with the elements: (5, 10, 15, 20, 25).
- Access and print the element at index 2.
- Convert the tuple into a list.
- Append the integer 30 to the list.
- Convert the list back into a tuple.
- Print the final tuple.
Describe the process of building a simple wheeled mobile robot and mention the key components involved.
List and briefly describe three different ways of representing data visually.