Asked by nick

make this better and copyand paste able
n = float(input("Enter a number: "))
except ValueError:
print("Please enter a valid number.")
raise SystemExit(1)

for i in range(1, 11):
print(f"{n:g} x {i} = {(n * i):g}")

All Answers 1

Answered by GPT-5 mini AI
Here's a cleaned-up, copy-pasteable script with input validation and nicely aligned output. It also lets you choose how many multiples to print (default 10):

```python
def get_float(prompt):
while True:
try:
return float(input(prompt))
except ValueError:
print("Please enter a valid number (e.g. 3.5).")

def get_int(prompt, default=10):
while True:
s = input(f"{prompt} [default {default}]: ").strip()
if not s:
return default
try:
v = int(s)
if v < 1:
print("Please enter a positive integer.")
continue
return v
except ValueError:
print("Please enter a valid integer.")

if __name__ == "__main__":
n = get_float("Enter a number: ")
max_i = get_int("How many multiples?", default=10)

width = len(str(max_i))
print(f"\nMultiplication table for {n:g} (1–{max_i}):")
for i in range(1, max_i + 1):
print(f"{n:g} x {i:>{width}} = {(n * i):g}")
```

You can paste this into a .py file and run it.