Challenge: Optional Arguments
Swipe to start coding
Implementing a function add_user
to manage users in a database. If the user exists in users_db
, their fields should be updated instead of creating a new entry. If the user is not found, a new user should be added with the provided details.
- Define the
add_user
function with parametersname
,age
,role
(default is "user"), andstatus
(default is "active"). - Check if a user with the same
name
exists in theusers_db
list. - If the user exists, update their
age
,role
, andstatus
with the values received as arguments in theadd_user
function. - Return the string
"User {name} updated successfully!"
after updating the user. - If the user doesn't exist, create a new user (
new_user
) with the provided details(name
,age
,role
,status
). - Add the new user (
new_user
) to listusers_db
. - Return the string
"User {name} added successfully!"
after adding the new user.
Lösning
Tack för dina kommentarer!
single
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Can you explain this in more detail?
What are the next steps I should take?
Can you give me an example?
Awesome!
Completion rate improved to 4.35
Challenge: Optional Arguments
Svep för att visa menyn
Swipe to start coding
Implementing a function add_user
to manage users in a database. If the user exists in users_db
, their fields should be updated instead of creating a new entry. If the user is not found, a new user should be added with the provided details.
- Define the
add_user
function with parametersname
,age
,role
(default is "user"), andstatus
(default is "active"). - Check if a user with the same
name
exists in theusers_db
list. - If the user exists, update their
age
,role
, andstatus
with the values received as arguments in theadd_user
function. - Return the string
"User {name} updated successfully!"
after updating the user. - If the user doesn't exist, create a new user (
new_user
) with the provided details(name
,age
,role
,status
). - Add the new user (
new_user
) to listusers_db
. - Return the string
"User {name} added successfully!"
after adding the new user.
Lösning
Tack för dina kommentarer!
Awesome!
Completion rate improved to 4.35single