Jan-21-2021, 01:32 PM
I need help please.
I am trying to learm Python and work with Python 3.83.5 using How To Think Like A Computer Scientist as a guide. I am at Chapter 7 Encapsulation and have the following working function?
1 for i in range(1, 7):
2 print_multiples(i)
Notice how similar this loop is to the one inside print_multiples. All we did was replace the print function with a function call'
Now I have tried to replace each print statement in the function print_multiples(n)but cannot get the function to work. Can anyone please advise what to do.
The output of this program is a multiplication table:
1 2 3 4 5 6
2 4 6 8 10 12
3 6 9 12 15 18
4 8 12 16 20 24
5 10 15 20 25 30
6 12 18 24 30 36
I am trying to learm Python and work with Python 3.83.5 using How To Think Like A Computer Scientist as a guide. I am at Chapter 7 Encapsulation and have the following working function?
n = 3 def print_multiples(n): for i in range(1, 7): print(n * i, end=" ") print() print(print_multiples(n))The next stage is (quote) 'By now you can probably guess how to print a multiplication table — by calling print_multiples repeatedly with different arguments. In fact, we can use another loop:
1 for i in range(1, 7):
2 print_multiples(i)
Notice how similar this loop is to the one inside print_multiples. All we did was replace the print function with a function call'
Now I have tried to replace each print statement in the function print_multiples(n)but cannot get the function to work. Can anyone please advise what to do.
The output of this program is a multiplication table:
1 2 3 4 5 6
2 4 6 8 10 12
3 6 9 12 15 18
4 8 12 16 20 24
5 10 15 20 25 30
6 12 18 24 30 36