string = "ABCDEFG"
counter = 0
for i in range(len(string)):
if string[i] == 'C ':
print(counter)
else:
counter += 1
2
def is_palindrome(input_string):
return input_string == input_string[::-1]
input_string = input("Enter a string: ")
if is_palindrome(input_string) == True:
print(f"{input_string} is a palindrome.")
else:
print(f"{input_string} is not a palindrome.")
Racecar is a palindrome.
def binary_search(arr, target):
left = 0
right = len(arr) - 1
while left <= right:
mid = (left + right) // 2
mid_value = arr[mid]
if mid_value == target:
return mid
elif mid_value < target:
left = mid + 1
else:
right = mid - 1
return -1
arr = [1, 3, 5, 7, 9, 11, 13]
target = 1
result = binary_search(arr, target)
if result != -1:
print(f"Element {target} found at index {result}")
else:
print(f"Element {target} not found in the array")
Element 1 found at index 0