#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
Asked
Active
Viewed 55 times
-2

chepner
- 497,756
- 71
- 530
- 681

masroor_rajput
- 5
- 1
-
1What "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
-
1It'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 Answers
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
-
-
-
-
@masroor_rajput - see my update, now `table2 ` is the variable name containing multiplication table of 2. – AboAmmar Jun 09 '22 at 20:42
-
@masroor_rajput *what* do you want, exactly? Some advice, you want to at least tell us the *type* of the object and it's value. The "table" isn't anything, that is simply what you printed to the screen. – juanpa.arrivillaga Jun 09 '22 at 20:47