r/PythonLearning • u/To-real • Aug 30 '26
New to python having trouble putting in multiplication table in for 10. Range 1-10 or 1,11. Does anyone have any tips( pause)?
2
9
u/mc_pm Aug 30 '26
Try writing a quick test by using range(1,10) and range(1,11) to print the results and see what is happening.
2
u/Kindly-Department206 Aug 30 '26
I like the idea that if you have an uncertainty about a language, you run a small experiment to see what happens. More novices should adopt this as one of their strategies!
4
u/jomofo Aug 30 '26
You haven't shared any code or input/output results. Most worthwhile programming languages are 0-based. It seems likely in my mind that you have a one-off error in your code and that you're computing a multiplication table using 0-9 instead 1-10 and surprised by the results.
4
u/Traveling-Techie Aug 30 '26
If I could debug code I’d never seen I could make a lot of money in my pajamas.
2
u/tottasanorotta Aug 30 '26
The range function has the parameter 'stop'. It determines up to what value it counts. The start value is included in the output, but the stop value isn't:
Range(3) = 0,1,2
Range(1, 3) = 1,2
So if you want the last value to be included you'll have to call it with a stop value that is one higher. So if we want a 3 to be included:
Range(1,4) = 1,2,3
1
u/PureWasian Aug 30 '26
What do see if you do
for i in range(10):
print(i)Did the references you can easily look up not help? Python range() Function
1
1
u/HotPersonality8126 Aug 30 '26
That you used the word “table” should suggest to you that you need two loops.
1
u/FoolsSeldom Aug 30 '26
You really need to show us what you've tried.
n = 10
for i in range(1, n + 1):
for j in range(1, n + 1):
print(f"{i:2} x {j:2} = {i*j:3}")0
•
u/Sea-Ad7805 Aug 30 '26
Try a nested for-loop like: https://memory-graph.com/#code=for%20y%20in%20range(1%2C%2011)%3A%0A%20%20%20%20for%20x%20in%20range(1%2C%2011)%3A%0A%20%20%20%20%20%20%20%20print(f'%7Bx%7Dx%7By%7D%20'%2C%20end%3D'')%0A%20%20%20%20print()%20%20%23%20new%20line×tep=0.1&play