Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Output a Certain Row of the Multiplication Table

Python Output a Certain Row of the Multiplication Table

Document Object Reference Manual Python3 Examples

We can write a Python function to output a certain row of the multiplication table. This function will accept a parameter nrepresenting the row number to output (between 1 and 9). The function will output that row's multiplication table content.

Example

def

print_multiplication_row

(

n

)

:

   

for

i

in

range

(

1

,

10

)

:

       

print

(

f

"{n} * {i} = {n * i}"

)

Code analysis:

Output result: Suppose we call print_multiplication_row(3), the output will be:

3 * 1 = 3
3 * 2 = 6
3 * 3 = 9
3 * 4 = 12
3 * 5 = 15
3 * 6 = 18
3 * 7 = 21
3 * 8 = 24
3 * 9 = 27

Document Object Reference Manual Python3 Examples