Computers and Technology
Computers and Technology, 05.01.2022 09:50, kiasiab17

Creating new instances of class objects can be a great way to keep track of values using attributes associated with the object. The values of these attributes can be easily changed at the object level. The following code illustrates a famous quote by George Bernard Shaw, using objects to represent people. Fill in the blanks to make the code satisfy the behavior described in the quote. # "If you have an apple and I have an apple and we exchange these apples then
# you and I will still each have one apple. But if you have an idea and I have
# an idea and we exchange these ideas, then each of us will have two ideas."
# George Bernard Shaw

class Person:
apples = 0
ideas = 0

johanna = Person()
johanna. apples = 1
johanna. ideas = 1

martin = Person()
martin. apples = 2
martin. ideas = 1

def exchange_apples(you, me):
#Here, despite G. B. Shaw's quote, our characters have started with
#different amounts of apples so we can better observe the results.
#We're going to have Martin and Johanna exchange ALL their apples with #one another.
#Hint: how would you switch values of variables,
#so that "you" and "me" will exchange ALL their apples with one another?
#Do you need a temporary variable to store one of the values?
#You may need more than one line of code to do that, which is OK.
Temp = you. apples
you. appples = me. apples
me. apples = Temp

return you. apples == me. apples

def exchange_ideas(you, me):
#"you" and "me" will share our ideas with one another.
#What operations need to be performed, so that each object receives
#the shared number of ideas?
#Hint: how would you assign the total number of ideas to
#each idea attribute? Do you need a temporary variable to store
#the sum of ideas, or can you find another way?
#Use as many lines of code as you need here.
temp = you. ideas
you. ideas += me. ideas
me. ideas += temp

return you. ideas, me. ideas

exchange_apples(johanna, martin)
print("Johanna has {} apples and Martin has {} apples".format(johanna. apples, martin. apples))
exchange_ideas(johanna, martin)
print("Johanna has {} ideas and Martin has {} ideas".format(johanna. ideas, martin. ideas))

Johanna has 1 apples and Martin has 1 apples
Johanna has 2 ideas and Martin has 2 ideas

below is an error:

Not quite. Did you properly add or equivalate the attributes
of both instances of the Person() class?

Can you help me why is and show step by step in python crash course

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 23:00, nicog94
In which part of a professional email should you try to be brief, but highly descriptive?
Answers: 1
image
Computers and Technology, 22.06.2019 23:50, Emptypockets451
You need to design a circuit that implements the functions in the following table: s0 s1 function0 0 a + 10 1 a – b1 0 a + b1 1 a – 1s0 and s1 are 1-bit control inputs to select the function of the circuit. inputs a and b are 4-bitnumbers in 2s complement form. the output is also a 4-bit number in 2s complement form. you are allowed to use only one ttl 7483 4-bit adder to implement all the functions. but anynumber of other components (except the adder) can be used. hint: design a combinational logic circuit to modify the input b and the “carry input” of theadder depending on the control inputs s0 and s1.important: lab grade will depend on the working of the circuit & will be checked of by your labinstructor.1. is the output valid for the following input combinations: a. s0 = 0, s1 = 0, a = 7, b = 3? b. s0 = 0, s1 = 1, a = 7, b = 3? c. s0 = 1, s1 = 0, a = -4, b = -5? d. s0 = 1, s1 = 1, a = -8, b = 6? 2. what is the range of inputs (for both a and b) that will produce the valid output for all the functions?
Answers: 3
image
Computers and Technology, 23.06.2019 11:00, jaygamer37
What is the name of the sound effect that danny hears
Answers: 1
image
Computers and Technology, 23.06.2019 19:30, bbgirl8638
Of the following pieces of information in a document, for which would you most likely insert a mail merge field?
Answers: 3
Do you know the correct answer?
Creating new instances of class objects can be a great way to keep track of values using attributes...

Questions in other subjects:

Konu
Mathematics, 21.01.2021 17:30
Konu
Mathematics, 21.01.2021 17:30
Konu
Mathematics, 21.01.2021 17:30