Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Positional Arguments | Positional and Optional Arguments
Python Functions Tutorial

bookChallenge: Positional Arguments

Task

Swipe to start coding

Implement the register_user function to validate a user's age and add them to the database.

  1. Define the function register_user with the parameters username, email, and age.
  2. Inside the function, check if age is less than 18. If so, return the message "Registration failed: age must be 18 or older.".
  3. Create a dictionary named user with keys "username", "email", and "age". Assign the function parameters (username, email, age) as the values for these keys.
  4. Add the user dictionary to the users_db list.
  5. Return the message "User {username} registered successfully!" using the actual username.
  6. Call register_user passing specific values (arguments) for a test user.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 2
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

bookChallenge: Positional Arguments

Swipe to show menu

Task

Swipe to start coding

Implement the register_user function to validate a user's age and add them to the database.

  1. Define the function register_user with the parameters username, email, and age.
  2. Inside the function, check if age is less than 18. If so, return the message "Registration failed: age must be 18 or older.".
  3. Create a dictionary named user with keys "username", "email", and "age". Assign the function parameters (username, email, age) as the values for these keys.
  4. Add the user dictionary to the users_db list.
  5. Return the message "User {username} registered successfully!" using the actual username.
  6. Call register_user passing specific values (arguments) for a test user.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 2
single

single

some-alt