Question

class User:
active = True

def __init__(self,name,age,height,weight,level_of_fitness):
self.name = name
self.age = age
self.height = height
self.weight = weight
self.level_of_fitness = level_of_fitness
self.activities = []

def cancel(self):
self.active = False
print(f"{self.name} has cancelled their account.")

def add_activity(self,activity):
# Check for active membership
if self.active:
self.activities.append(activity)
print(f"{self.name} decided to try {activity} today!")
else:
print(f"{self.name} has an inactive account. Please activate in order to add more activities.")

def reactivation(self):
if self.active:
print(f"{self.name} already has an active account.")
else:
self.active = True
print(f"Welcome back, {self.name}! We're happy to have you back on board the KeepMoving app!")

def __str__(self):
return f"{self.name} is {self.age} years old, {self.height} in inches tall, weighs {self.weight} lbs, and has a level of fitness of {self.level_of_fitness}. Personal Trainer: {trainer}. Account active? {self.active}"

jerry = User("Jerry",22,72,175,7)
susan = User("Susan",31,67,110,10)
rick = User("Rick",19,62,145,3)

print(jerry)
print(susan)
print(rick)

jerry.add_activity("cycling")
print(jerry.activities)

jerry.cancel()
jerry.add_activity("weight lifting")
print(jerry.activities)

jerry.reactivation()
jerry.add_activity("weight lifting")
print(jerry.activities)

print(jerry)
trainer = "Mr. Simmons"
print(susan)
print(rick)

jerry.reactivation()
print(jerry)

In the example above, how many methods are included in the User Class?(1 point) Responses 2 2 3 3 5 5 6

Answers

Answered by GPT-4o mini
In the provided `User` class, there are 5 methods defined:

1. `__init__()` - Constructor method to initialize the user object.
2. `cancel()` - Method to cancel the user's account.
3. `add_activity(activity)` - Method to add an activity if the account is active.
4. `reactivation()` - Method to reactivate the user's account if it was canceled.
5. `__str__()` - Method to return a string representation of the user object.

So the answer is **5**.
There are no human answers yet. A form for humans to post answers is coming very soon!

Related Questions