![chandranewlon](/avatars/9960.jpg)
chandranewlon
04.08.2020 •
Computers and Technology
#Below is a class representing a person. You'll see the
#Person class has three instance variables: name, age,
#and GTID. The constructor currently sets these values
#via a calls to the setters.
#
#Create a new function called same_person. same_person
#should take two instances of Person as arguments, and
#returns True if they are the same Person, False otherwise.
#Two instances of Person are considered to be the same if
#and only if they have the same GTID. It does not matter
#if their names or ages differ as long as they have the
#same GTID.
#
#You should not need to modify the Person class.
class Person:
def __init__(self, name, age, GTID):
self.set_name(name)
self.set_age(age)
self.set_GTID(GTID)
def set_name(self, name):
self.name = name
def set_age(self, age):
self.age = age
def set_GTID(self, GTID):
self.GTID = GTID
def get_name(self):
return self.name
def get_age(self):
return self.age
def get_GTID(self):
return self.GTID
#Add your code below!
#Below are some lines of code that will test your function.
#You can change the value of the variable(s) to test your
#function with different inputs.
#
#If your function works correctly, this will originally
#print: True, then False.
person1 = Person("David Joyner", 30, 901234567)
person2 = Person("D. Joyner", 29, 901234567)
person3 = Person("David Joyner", 30, 903987654)
print(same_person(person1, person2))
print(same_person(person1, person3))
Solved
Show answers
More tips
- P Philosophy Agnosticism: Opinion or Belief?...
- C Computers and Internet How to Calibrate Your Monitor: Useful Tips and Recommendations...
- H Health and Medicine Hangover: How to Get Rid of It Quickly?...
- A Auto and Moto How to Start a Diesel Engine in Cold Weather?...
- A Auto and Moto Which alarm system to choose?...
- P Photography and Videography What is lens calibration and why is it needed?...
- S Science and Technology How to Choose a Picture Frame: Tips and Recommendations...
- P Photography and Videography Understanding HDR: How It Works and Why You Need It...
- P Photography and Videography How to Choose the Perfect Photo Paper for Your Images?...
- C Computers and Internet How to Choose an Uninterruptible Power Supply (UPS) for Your Computer: Expert Tips...
Answers on questions: Computers and Technology
- C Computers and Technology Ryan is designing an app that needs to quickly send low quality photos between users. Most smartphones take much higher quality photos than Ryan needs for his app. Which...
- C Computers and Technology Ugh im Bored... guys, who wanna ch at on pinterest? Pinterest name and username below, also my Pinterest pfp is the same as this one. Username: HelloStarCat Name: Star Cat....
- B Business Carla Vista Inc. has the following information related to an item in its ending inventory. Product 66 has a cost of $152, a replacement cost of $143, a net realizable value...
- C Computers and Technology Write a program that asks a user to roll a single die twice to get a sum value of 7. If the sum is 11, the user loses. If the sum is neither 7 nor 11, the user neither wins...
- B Business Leanne, a franchisee, runs a chain of small restaurants with a well-known name. Due to her hard work and people skills, her locations are doing quite well. She has noticed...
- E Engineering The total cooling load for a building zone is 200,000 Btu/hr with a sensible heat ratio (SHR) of 0.8. The zone temperature is 74F. The supply air is at a temperature of...
- E English We created an essential communication system that assisted to bind neighbors and families into one nation. This sentence from paragraph 2 is an example of a... * A. chemical...
- M Mathematics Help pls I give a really good rating....
- B Business On July 1, 2017, Wyler Company placed a new asset into service. The cost of the asset was $90,000 with an estimated 9-year life and a $9,000 salvage value. Assuming a fiscal...
- M Mathematics A researcher claims that the mean cost of raising a child from birth to age 2 by husbandwife families in the U.S. is $13,960. A random sample of 500 children (age 2) has...
Ответ:
Here is the function same_person that takes two instances of Person as arguments i.e. p1 and p2 and returns True if they are the same Person, False otherwise.
def same_person(p1, p2): #definition of function same_person that takes two parameters p1 and p2
if p1.GTID==p2.GTID: # if the two instances of Person have same GTID
return True #returns true if above condition evaluates to true
else: #if the two instances of Person do not have same GTID
return False #returns false when two persons have different GTID
Explanation:
person1 = Person("David Joyner", 30, 901234567) #first instance of Person
person2 = Person("D. Joyner", 29, 901234567) #second instance of Person
person3 = Person("David Joyner", 30, 903987654) #third instance of Person
print(same_person(person1, person2)) #calls same_person method by passing person1 and person2 instance of Person to check if they are same
print(same_person(person1, person3)) #calls same_person method by passing person1 and person3 instance of Person to check if they are same
The function works as follows:
For function call print(same_person(person1, person2))
The GTID of person1 is 901234567 and that of person2 is 901234567
If condition if p1.GTID==p2.GTID in the function same_person checks if the GTID of person1 is equal to the GTID of person2. This condition evaluates to true because GTID of person1 = 901234567 and GTID of person2 = 901234567
So the output is:
True
For function call print(same_person(person1, person3))
The GTID of person1 is 901234567 and that of person3 is 903987654
If condition if p1.GTID==p2.GTID in the function same_person checks if the GTID of person1 is equal to the GTID of person3. This condition evaluates to false because GTID of person1 = 901234567 and GTID of person2 = 903987654 and they are not equal
So the output is:
False
The complete program along with its output is attached in a screenshot.
Ответ:
The answer is letter B