Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function encapsulation
#1
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?

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
Reply


Messages In This Thread
Function encapsulation - by Oldman45 - Jan-21-2021, 01:32 PM
RE: Function encapsulation - by spaceraiders - Jan-21-2021, 01:34 PM
RE: Function encapsulation - by BashBedlam - Jan-21-2021, 03:33 PM
RE: Function encapsulation - by Oldman45 - Jan-22-2021, 11:32 AM
RE: Function encapsulation - by Oldman45 - Jan-22-2021, 11:38 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Encapsulation codinglearner 2 2,146 Apr-02-2024, 01:26 PM
Last Post: DataScience
  Preserve Encapsulation while Displaying Information QueenSvetlana 13 9,244 Dec-07-2017, 06:13 PM
Last Post: snippsat
  Encapsulation issue iFunKtion 4 4,877 Mar-07-2017, 10:13 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020