0

So I wrote this fx to make me "multiplication tables", I finally got everything right including the formating. Except the that when I call my fx it prints none after the table. Now I know you can by pass that using return but I can't use return here (am I correct because returning more than one variable from an fx makes a tuple???? I couldn't "unpack" this tuple. Anyways here how do I stop the none from printing?

[IN]:



def multitables(n):
    for i in range(1, n+1):
        print(end="\n")  
        for j in range(1, n+1):
            print (j, i, i*j, end="\t") 

print(multitables(3))

[OUT]: 
1 1 1   2 1 2   3 1 3   
1 2 2   2 2 4   3 2 6   
1 3 3   2 3 6   3 3 9   None

My table has to be formatted this way. I tried using this format thing I found the last line of my code would change to this.

print ("{0} {1} {2}".format(j, i, i*j), 

But it doesn't do anything. Any input would be great!

Thanks.

Rache;

Rachel Cyr
  • 429
  • 1
  • 5
  • 15

1 Answers1

2

The None at the end is coming from print-ing the result of multitables itself (since it has no return, the return value is None)

To remove the None, don't print the result of the call:

multitables(3)

Should give:

1 1 1   2 1 2   3 1 3   
1 2 2   2 2 4   3 2 6   
1 3 3   2 3 6   3 3 9
rdas
  • 20,604
  • 6
  • 33
  • 46