Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Optional Arguments | Section
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Python Functions

bookChallenge: Optional Arguments

Task

Swipe to start coding

You are working with a simple user management system. Your goal is to implement a function add_user() that adds new users or updates existing ones in a global list called users_db.

  • Define a function add_user(name, age, role="user", status="active").
  • Loop through the list users_db to check if a user with the same name already exists.
  • If the user exists, update their details. Then return the message: "User {name} updated successfully!".
    • "age"age.
    • "role"role.
    • "status"status.
  • If the user doesn't exist, create a new dictionary named new_user with the provided details (name, age, role, status), append it to users_db, and return: "User {name} added successfully!".

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 11
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

bookChallenge: Optional Arguments

Swipe to show menu

Task

Swipe to start coding

You are working with a simple user management system. Your goal is to implement a function add_user() that adds new users or updates existing ones in a global list called users_db.

  • Define a function add_user(name, age, role="user", status="active").
  • Loop through the list users_db to check if a user with the same name already exists.
  • If the user exists, update their details. Then return the message: "User {name} updated successfully!".
    • "age"age.
    • "role"role.
    • "status"status.
  • If the user doesn't exist, create a new dictionary named new_user with the provided details (name, age, role, status), append it to users_db, and return: "User {name} added successfully!".

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 11
single

single

some-alt