script_3.py - Multiplication Table
Code
Python
#!/usr/bin/env python3
"""Multiplication table"""
num = int(input("Enter a number: "))
for i in range(1, 11):
print(f"{num} x {i} = {num * i}")
Explanation
Line 4: num = int(input("Enter a number: "))
- num stores the integer we want multiplication table for
- Remains constant throughout loop (not modified)
Line 6: for i in range(1, 11):
- Iterates from 1 to 10
- i is the multiplier that changes each iteration
Line 7: print(f"{num} x {i} = {num * i}")
- Three placeholders in one f-string: {num}, {i}, {num * i}
- num * i performs multiplication inside the placeholder
- Expression is evaluated before printing
- Each iteration prints one line of the table
- Example if num=5: "5 x 1 = 5", "5 x 2 = 10", etc.