Can't run a function with in a function with loop

i just want to try to run a function with in a function with loop.but i made some mistakes.
plese tell me which mistake I made and where i need to run a loop in my code.

def d(individuals):






def team(name=“delhi”):

print(individuals+" belong from "+ name)



team(name=“knight rider”)



In your code as far as I can understand is that you one function ‘d’ to print the name of the individual which you want to use in the second function ‘team’ in its print statement.
If this is the case then your ‘d’ function seems to perfectly alright.
But in second function you are trying to call the value of individual without passing it into the function ‘team’ . therefore your ‘team’ function definition will contain the argument as individual also. and while calling ‘team’ you need to pass the value of individual also.

Or else please specify what output do you want and then we can decide how can we use loop in this…!!

Yes sir.
I just want to call Function ‘d’ in the function ‘team’ ,and I want a Output like “kohli belong from Bengalore” ,“dhoni belong from Chennai” and So on.
Please help me to solve it…
Thank you Sir

Is this what you expected as the result?

# Class IPL groups attributes of data and methods
class IPL:
    # player name, player team are attributes of data associated with class IPL
    def __init__(self, playername, playerteam):
        self.p_name = playername
        self.p_team = playerteam
    # team_play is a function associated with class IPL
    def team_play(self):
        # {} are called place holders and format method returns the arguments
        # such as p_name, "is from team", p_team
        return'{} {} {}'.format(self.p_name, "is from team", self.p_team)
# player_one, player_two, player_three, player_four are instances of class IPL
player_one = IPL("KHOLI", "BANGALORE")
player_two = IPL("DHONI", "CHENNAI")
player_three = IPL("SOURAV", "KOLKATTA")
player_four = IPL("SEHWAG", "DELHI")
# players is of type list
players = [player_one, player_two, player_three, player_four]
# for each player in the list players the loop prints 
for player in players:
1 Like

Yes Sir…
I want this output.
But I can’t get the codes,Specialy curve braces,and format.
If you don’t mind,Can you explain it a little bit .
Thank you for your kind attention.

Kindly refer the comments added to the code.
Refer this ( for knowing more about Format method.

1 Like