import matplotlib.pyplot as plt
def collatz_conjecture(n):
sequence = [n]
while n != 1:
if n % 2 == 0:
n = n // 2
else:
n = 3 * n + 1
sequence.append(n)
return sequence
def plot_collatz(n):
sequence = collatz_conjecture(n)
plt.plot(sequence, linestyle='-', marker='o', markersize=3, color='darkcyan')
plt.xlabel('Step')
plt.ylabel('Value')
plt.title('Collatz conjecture')
plt.grid(True)
plt.show()
plot_collatz(27)