Challenge: Working with Instance and Class Variables
Task
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.
Solution
Everything was clear?
Thanks for your feedback!
Section 1. Chapter 7
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 3.85
Challenge: Working with Instance and Class Variables
Swipe to show menu
Task
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.
Solution
Everything was clear?
Thanks for your feedback!
Section 1. Chapter 7