Challenge: Working with Instance and Class Variables
Oppgave
Swipe to start coding
Define a class named User with the following requirements:
- Create a class variable
total_usersand initialize it to0. - Implement the
__init__method to:- Take
usernameas an argument. - Store
usernameas an instance variable. - Increment
total_usersby1every time a newUserinstance is created.
- Take
- Implement a method
get_infothat returns a tuple containing:- The user's name (the value of the instance variable for username).
- The current value of
total_users.
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 7
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Fantastisk!
Completion rate forbedret til 3.85
Challenge: Working with Instance and Class Variables
Sveip for å vise menyen
Oppgave
Swipe to start coding
Define a class named User with the following requirements:
- Create a class variable
total_usersand initialize it to0. - Implement the
__init__method to:- Take
usernameas an argument. - Store
usernameas an instance variable. - Increment
total_usersby1every time a newUserinstance is created.
- Take
- Implement a method
get_infothat returns a tuple containing:- The user's name (the value of the instance variable for username).
- The current value of
total_users.
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 7