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

Stryg for at vise menuen

book
Challenge: Positional Arguments

Opgave

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.

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 2. Kapitel 2

Spørg AI

expand
ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

book
Challenge: Positional Arguments

Opgave

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.

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 2. Kapitel 2
Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Vi beklager, at noget gik galt. Hvad skete der?
some-alt