Issue
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;
Solution
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
Answered By - rdas Answer Checked By - Marie Seifert (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.