import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 2 * np.pi, 200)
y = np.sin(x)
plt.figure(figsize=(8, 3))
plt.plot(x, y, color='#3b82f6', linewidth=2)
plt.title('Sine Wave')
plt.show()
▶[ ]
defcount_char(text, char):
returnsum(1for c in text if c == char)
word = input("Enter a word: ")
char = input("Character to count: ")
print(f"'{'{'}char{'}'}' appears {'{'}count_char(word, char){'}'} times")
▶[ ]
defbinary_search(arr, target):
lo, hi = 0, len(arr) - 1while lo <= hi:
mid = (lo + hi) // 2if arr[mid] == target:
return mid
elif arr[mid] < target:
lo = mid + 1else:
hi = mid - 1return -1