Challenge: Positional Arguments
Task
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_userthat 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_dblist using the appropriate method. - If everything is successful, return the message
"User {username} registered successfully!", where{username}is the actual username. - Call the
register_userfunction with example parameters for a user, either by passing arguments directly or as a dictionary.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 2. ChapterΒ 2
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 4.17
Challenge: Positional Arguments
Swipe to show menu
Task
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_userthat 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_dblist using the appropriate method. - If everything is successful, return the message
"User {username} registered successfully!", where{username}is the actual username. - Call the
register_userfunction with example parameters for a user, either by passing arguments directly or as a dictionary.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 2. ChapterΒ 2
single