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
course content

Course Content

Python Functions Tutorial

Python Functions Tutorial

1. What is a Function in Python?
2. Positional and Optional Arguments
3. Arbitrary Arguments
4. Function Return Value Specification
5. Recursion and Lambda Functions

book
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.

  1. Define the function register_user that takes parameters username, email, and age.
  2. 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."
  3. Create a dictionary user with the keys username, email, and age, and assign the corresponding values.
  4. Add the user dictionary to the users_db list using the appropriate method.
  5. If everything is successful, return the message "User {username} registered successfully!", where {username} is the actual username.
  6. Call the register_user function with example parameters for a user, either by passing arguments directly or as a dictionary.

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
toggle bottom row

book
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.

  1. Define the function register_user that takes parameters username, email, and age.
  2. 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."
  3. Create a dictionary user with the keys username, email, and age, and assign the corresponding values.
  4. Add the user dictionary to the users_db list using the appropriate method.
  5. If everything is successful, return the message "User {username} registered successfully!", where {username} is the actual username.
  6. Call the register_user function with example parameters for a user, either by passing arguments directly or as a dictionary.

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
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt