Challenge: Optional Arguments
Uppgift
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
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 2. Kapitel 4
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
Awesome!
Completion rate improved to 4.35
Challenge: Optional Arguments
Svep för att visa menyn
Uppgift
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
Var allt tydligt?
Tack för dina kommentarer!
Awesome!
Completion rate improved to 4.35Avsnitt 2. Kapitel 4
single