Question

trainer = "Mr. Brown"

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)

For the following questions, use the pictured class. (If you need to enlarge, try pressing "Ctrl" and the "=" key or "CMD" and the "=" key.)To interact with this code, you can make a copy of it here. VIDEO: You can also watch me build this class here. Question 1In the example above, which of the following statements is false?(1 point)ResponsesOn line 4, active is a global variable with a value of "True"On line 4, active is a  global  variable with a value of "True"The User class occupies lines 3 to 34.The User class occupies lines 3 to 34.This example instantiates three users.This example instantiates three users.On line 1, trainer is a global variable with a value of "Mr. Brown"On line 1, trainer is a global variable with a value of "Mr. Brown"Question 2In the example above, how many methods are included in the User Class?(1 point)Responses22335566Question 3In the example above, we execute the following print statement on line 49: Which activities are present in Jerry's activities list on this line?(1 point)Responses[ ][ ]['cycling']['cycling']['cycling','weight lifting']['cycling','weight lifting']['cycling','weight lifting','Mr. Brown']['cycling','weight lifting','Mr. Brown']Question 4In the example above, which line demonstrates the use of a local variable?(1 point)Responses114420203636Question 5In the example above, which lines represent users being instantiated? (1 point)ResponsesLine 51Line 51Line 40 to Line 42Line 40 to Line 42Line 36 to Line 38Line 36 to Line 38Line 6 to Line 12Line 6 to Line 12Question 6In the example above, there is a comment on line 19 that reads "# Check for active membership". This is text that will not be executed as code, but is there to provide a rationale for the code that follows it. If you were to add a comment on line 27 BEFORE the "if" statement, which of the following would be the best comment to include?(1 point)Responses# Check for active membership# Check for active membership# Local variable example# Local variable example# This is an if-statement# This is an if-statement# Global variable example# Global variable exampleQuestion 7Using the example above, drag and drop the answer choices to categorize the users based on who their trainer is at various stages of the output.(4 points)Put responses in the correct input to answer the question. Select a response, navigate to the desired input and insert the response. Responses can be selected and inserted using the space bar, enter key, left mouse button or touchpad. Responses can also be moved by dragging with a mouse.trainer = "Mr. Brown" trainer = "Mr. Simmons"Jerry at Line 40Jerry at line 55Rick at line 42Susan at line 57

Answers

Answered by GPT-4o mini
Here are the answers to the questions based on the provided code snippet:

**Question 1:** In the example above, which of the following statements is false?
**Response:** On line 4, active is a global variable with a value of "True"
(Explanation: `active` is a class variable, not a global variable.)

---

**Question 2:** In the example above, how many methods are included in the User Class?
**Response:** 5
(Explanation: The User class includes 5 methods: `__init__`, `cancel`, `add_activity`, `reactivation`, and `__str__`.)

---

**Question 3:** In the example above, we execute the following print statement on line 49: Which activities are present in Jerry's activities list on this line?
**Response:** ['cycling', 'weight lifting']
(Explanation: Jerry has added "cycling" and "weight lifting" as activities.)

---

**Question 4:** In the example above, which line demonstrates the use of a local variable?
**Response:** 20
(Explanation: Inside the `add_activity` method, the parameter `activity` is a local variable.)

---

**Question 5:** In the example above, which lines represent users being instantiated?
**Response:** Line 36 to Line 38
(Explanation: Lines 36 to 38 show the instantiation of the three User objects — jerry, susan, and rick.)

---

**Question 6:** If you were to add a comment on line 27 BEFORE the "if" statement, which of the following would be the best comment to include?
**Response:** # Check for active membership
(Explanation: This comment reflects what the following code is meant to check.)

---

**Question 7:** Categorize the users based on who their trainer is at various stages of the output:
- **trainer = "Mr. Brown"**
- Jerry at Line 40
- Rick at Line 42
- Susan at Line 44

- **trainer = "Mr. Simmons"**
- Jerry at line 55
- Susan at line 57

(Explanation: At the start, Mr. Brown is the assigned trainer, and later on, Mr. Simmons is designated as the trainer, specifically noted in the output for Jerry at line 55.)

---

If you have any more questions or need further clarification on any of the answers, feel free to ask!

Related Questions