-3

I wrote this code which gives multiplication table .But in output I get 'none' ,what should I do to not get 'none'

def table(n):
    for i in range(1,6):
        j=i*n
        x = print(f"{i} * {n} = {j}")
    return x
print(table(int(input("enter the number :"))))

output

enter the number :4
1 * 4 = 4
2 * 4 = 8
3 * 4 = 12
4 * 4 = 16
5 * 4 = 20
None

What should I do to not get 'None'

2 Answers2

2

Try without writing print twice, also try without returning x:

def table(n):
    for i in range(1,6):
        j=i*n
        print(f"{i} * {n} = {j}")
table(int(input("enter the number :")))
U13-Forward
  • 69,221
  • 14
  • 89
  • 114
  • "Writing `print` twice" is far from the reason why the OP is getting 'None` in the output. – blhsing Aug 20 '21 at 07:22
  • Your edit still does not address why the OP is getting `None`. "Writing `print` twice" really simply has no direct relevance to the OP's issue. – blhsing Aug 20 '21 at 07:29
0

You are assigning the print function to x. Since print returns None, you are assigning x None, then you are returning x.

Also, return will end the function so don't use return

And also, remove the print function from the print(table.....

def table(n):
    for i in range(1,6):
        j=i*n
        print(f"{i} * {n} = {j}")
table(int(input("enter the number :")))