Forloop
Mon 21 July 2025
# Step 1: Import time for delay demo
import time
print("π Welcome to the Square Generator")
# Step 4: Start loop
for i in range(1, 11):
# Loop Step 1
print(f"π Looping... i = {i}")
# Pause for visibility
time.sleep(0.2)
# Calculate square
square = i ** 2
# Print square
print(f"π’ Square of {i} is {square}")
# After loop: show summary
print("β
Loop complete")
# Now letβs visualize the data
import matplotlib.pyplot as plt
x = list(range(1, 11))
y = squares
plt.plot(x, y, marker='o')
plt.title("Squares of Numbers")
plt.xlabel("Number")
plt.grid(True)
plt.show()
# Let's show individual items again for recap
for index, value in enumerate(squares):
print(f"{index+1}^2 = {value}")
squares2 = [i**2 for i in range(1, 11)]
print("Using list comprehension:", squares2)
print("π Program Finished!")
π Program Finished!
Score: 20
Category: basics