2

I want to have a tool that outputs me a multiplication table. so I writhe this:

def multiplicationTable(number):
    for x in range(1, 11):
        result = number * x
        print(f'{number} X {x} = {result}')

result = multiplicationTable(5)
print(result)

This returned me a multiplication table as expected but followed by an extra None type value.

5 X 1 = 5
5 X 2 = 10
5 X 3 = 15
5 X 4 = 20
5 X 5 = 25
5 X 6 = 30
5 X 7 = 35
5 X 8 = 40
5 X 9 = 45
5 X 10 = 50
None

why is that happening.

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149

1 Answers1

2

multiplicationTable(number) has no return value.

By default, when no return value is given, a python function will return None to signify that it was successfully executed. You have the same behavior in other languages.

To illustrate this, I made your function return something at the end :

def multiplicationTable(number):
    for x in range(1, 11):
        result = number * x
        print(f'{number} X {x} = {result}')
    return 'I have finished'

result = multiplicationTable(5)
print(result)

Output :

5 X 1 = 5
5 X 2 = 10
5 X 3 = 15
5 X 4 = 20
5 X 5 = 25
5 X 6 = 30
5 X 7 = 35
5 X 8 = 40
5 X 9 = 45
5 X 10 = 50
I have finished
Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
madjaoue
  • 5,104
  • 2
  • 19
  • 31