import time
text = ["H", "e", "l", "l", "o", "W", "o", "r", "l", "d", "!"]
toPrint = ""
for x in range(0, len(text)):
toPrint += text[x]
print(toPrint, end="\r")
time.sleep(0.4)
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.")
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 not found in the array
def describe_life_stage(stage, max_stage):
life_stages = ["Born", "Learn", "Make Money", "Buy House", "Retire"]
# Base case: when stage equals max_stage
if stage == max_stage:
print(life_stages[stage])
return
# Recursive case
print(life_stages[stage])
describe_life_stage(stage + 1, max_stage)
# Call the function starting from stage 0
describe_life_stage(0, 4)
Born
Learn
Make Money
Buy House
Retire