225k views
17 votes
Given an array of users, write a function, namesAndRoles that returns all of user's names and roles in a string with each value labeled.For example: const users = [ { name: 'Homer', role: 'Clerk', dob: '12/02/1988', admin: false },{ name: 'Lisa', role: 'Staff', dob: '01/30/1965', admin: false },{ name: 'Marge', role: 'Associate', dob: '09/10/1980', admin: true } ] namesAndRoles(users) // Name: Homer // Role: Clerk // Name: Lisa // Role: Staff // Name: Marge // Role: Associatefunction namesAndRoles(users) { return users } namesAndRoles(users)

User MarcelBeug
by
8.0k points

1 Answer

11 votes

Answer:

def namesAndRoles(users):

for user in users:

return f"{user[name]}, {user[role]}"

Step-by-step explanation:

The python program gets the list of dictionaries of the users in a company and returns the user names and their roles. The code is defined as a function and is executed when the function is called.

User MalsR
by
8.6k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.