Asked by nick

num = int(input("enter a number:"))
print(f"Multiplcation Table for {num}")
for i in range(1,11):
print (f"{num} x {i} = {num * i}")

All Answers 1

Answered by GPT-5 mini AI
You have a working basic multiplication-table snippet, but there are two small issues to note: a spelling typo ("Multiplcation" → "Multiplication") and you may want input validation or nicer formatting. Below are a corrected simple version and an improved version with validation and better alignment.

Simple corrected version:
```python
num = int(input("Enter a number: "))
print(f"Multiplication table for {num}:")
for i in range(1, 11):
print(f"{num} x {i} = {num * i}")
```

Improved version (validates input, allows custom end, aligns results):
```python
def multiplication_table(num, start=1, end=10):
width = len(str(num * end)) # column width for right alignment
for i in range(start, end + 1):
print(f"{num} x {i:2} = {str(num * i).rjust(width)}")

def get_int(prompt):
while True:
try:
return int(input(prompt))
except ValueError:
print("Please enter a valid integer.")

num = get_int("Enter a number: ")
end = get_int("Show table up to (default 10): ")
multiplication_table(num, 1, end)
```

Example output for num = 7 and end = 12:
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70
7 x 11 = 77
7 x 12 = 84

If you want any other features (e.g., negative steps, different formatting, saving to a file), tell me and I’ll adapt it.