-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 :")))
U12-Forward
  • 65,118
  • 12
  • 70
  • 89
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 :")))