Challenge: Positional Arguments
Uppgift
Swipe to start coding
Implement the register_user
function that checks the user's age, adds their details to a database (users_db
), and returns a success or failure message.
- Define the function
register_user
that takes parametersusername
,email
, andage
. - Inside the function
register_user
, check if age is less than 18. If it is, return the message"Registration failed: age must be 18 or older."
- Create a dictionary user with the keys
username
,email
, andage
, and assign the corresponding values. - Add the user dictionary to the
users_db
list using the appropriate method. - If everything is successful, return the message
"User {username} registered successfully!"
, where{username}
is the actual username. - Call the
register_user
function with example parameters for a user, either by passing arguments directly or as a dictionary.
Lösning
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 2. Kapitel 2
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.35Awesome!
Completion rate improved to 4.35
Challenge: Positional Arguments
Uppgift
Swipe to start coding
Implement the register_user
function that checks the user's age, adds their details to a database (users_db
), and returns a success or failure message.
- Define the function
register_user
that takes parametersusername
,email
, andage
. - Inside the function
register_user
, check if age is less than 18. If it is, return the message"Registration failed: age must be 18 or older."
- Create a dictionary user with the keys
username
,email
, andage
, and assign the corresponding values. - Add the user dictionary to the
users_db
list using the appropriate method. - If everything is successful, return the message
"User {username} registered successfully!"
, where{username}
is the actual username. - Call the
register_user
function with example parameters for a user, either by passing arguments directly or as a dictionary.
Lösning
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 2. Kapitel 2
single
Awesome!
Completion rate improved to 4.35
Challenge: Positional Arguments
Svep för att visa menyn
Uppgift
Swipe to start coding
Implement the register_user
function that checks the user's age, adds their details to a database (users_db
), and returns a success or failure message.
- Define the function
register_user
that takes parametersusername
,email
, andage
. - Inside the function
register_user
, check if age is less than 18. If it is, return the message"Registration failed: age must be 18 or older."
- Create a dictionary user with the keys
username
,email
, andage
, and assign the corresponding values. - Add the user dictionary to the
users_db
list using the appropriate method. - If everything is successful, return the message
"User {username} registered successfully!"
, where{username}
is the actual username. - Call the
register_user
function with example parameters for a user, either by passing arguments directly or as a dictionary.
Lösning
Var allt tydligt?
Tack för dina kommentarer!