-2
#first 
def table_(x):
    num=range(11)
    digit=int(input('Table of='))

    for num in range(11):
       # return(digit,'x',num,'=',num*digit)
        print(digit,'x',num,'=',num*digit)


num2=table_(2)
num2
chepner
  • 497,756
  • 71
  • 530
  • 681
  • 1
    What "return"? What are you wanting to return from the function? Unrelated, why do you take `x` as input to the function and never use it? Please explain what you are trying to do since we can't figure that out by backwards engineering broken code. – JNevill Jun 09 '22 at 18:56
  • 1
    It's not clear what you want. The assignment `num = range(11)` is irrelevant, because `num` is overwritten each time the loop iterates. What value should `num2` ultimately have? – chepner Jun 09 '22 at 18:56
  • I suspect some confusion over the difference between `return` and `print`; see https://stackoverflow.com/questions/750136/how-is-returning-the-output-of-a-function-different-from-printing-it, perhaps. – chepner Jun 09 '22 at 18:57
  • Your return value is `None` because your function doesnt explicitly return something so it will implicitly return `None` – juanpa.arrivillaga Jun 09 '22 at 20:46

1 Answers1

0

To print the multiplication table from 0 to 11 for example, you can modify your function like this:

def mul_table(digit):
    table = ''
    for num in range(12):
        table += f'{digit:2d} x {num:2d} = {num*digit:2d}\n'
    return table

Test with table of 2:

table2 = mul_table(2)
print(table2)
 2 x  0 =  0
 2 x  1 =  2
 2 x  2 =  4
 2 x  3 =  6
 2 x  4 =  8
 2 x  5 = 10
 2 x  6 = 12
 2 x  7 = 14
 2 x  8 = 16
 2 x  9 = 18
 2 x 10 = 20
 2 x 11 = 22
AboAmmar
  • 5,439
  • 2
  • 13
  • 24