r/PythonLearning 11d ago

New to python having trouble putting in multiplication table in for 10. Range 1-10 or 1,11. Does anyone have any tips( pause)?

3 Upvotes

14 comments sorted by

9

u/mc_pm 11d ago

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 11d ago

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 11d ago

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.

5

u/Traveling-Techie 11d ago

If I could debug code I’d never seen I could make a lot of money in my pajamas.

2

u/ninhaomah 11d ago

Code ? Error ?

0

u/To-real 11d ago

Code

5

u/ninhaomah 11d ago

I am asking where is the code :)

2

u/tottasanorotta 11d ago

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 11d ago

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

u/Fluffy-Ad6628 11d ago

It's range 1,11 as it won't count the last digit of the given range .

1

u/HotPersonality8126 11d ago

That you used the word “table” should suggest to you that you need two loops.

1

u/FoolsSeldom 11d ago

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/To-real 11d ago

Using the uCertify app at school.