In this chapter, we introduce a Python program that performs repetitive operations from 10 to 100 and displays the output in a structured table.
Initially, this task may be written with many lines of code, but in the next chapter, we’ll use loops to simplify and reduce the number of instructions.
This approach improves maintainability and readability.
# Generate repetition table from 10 to 100
print("--- Repetition Table from 10 to 100 ---")
for i in range(10, 101, 10):
print(f"Number: {i} | Square: {i**2} | Root: {i**0.5:.2f}")
--- Repetition Table from 10 to 100 ---
Number: 10 | Square: 100 | Root: 3.16
Number: 20 | Square: 400 | Root: 4.47
...
Number: 100 | Square: 10000 | Root: 10.00
- A for loop iterates from 10 to 100 in steps of 10
- For each number, the program prints its value, square, and approximate square root
- This method significantly reduces the number of lines compared to manual repetition