Awesome!
Completion rate improved to 4.17single
Challenge: Optional Arguments
Swipe to show menu
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.
Follow these steps:
-
Define a function
add_user(name, age, role="user", status="active"). -
Loop through the list
users_dbto check if a user with the same name already exists. -
If the user exists, update their details:
"age"βage."role"βrole."status"βstatus.
Then return the message:
"User {name} updated successfully!". -
If the user doesnβt exist, create a new dictionary named
new_userwith the provided details (name,age,role,status), append it tousers_db, and return:"User {name} added successfully!".
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat