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

Cursusinhoud

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

Taak

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.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 2
toggle bottom row

book
Challenge: Positional Arguments

Taak

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.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 2
Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Onze excuses dat er iets mis is gegaan. Wat is er gebeurd?
some-alt