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