Write the codes for the following exercises? ? ? ? 5.1.2 Coding Exercise 1 (External resource) (3.0
Fantastic news! We've Found the answer you've been seeking!
Question:
Write the codes for the following exercises?
?
?
?
Transcribed Image Text:
5.1.2 Coding Exercise 1 (External resource) (3.0 points possible) Phone.py 1 # Write a class named "Phone". The Phone class should 2 #have an attribute called "storage" which defaults to 3 #128, and an attribute called "color" which defaults 4 #to "red". 5 # 6 #Hint: 'attribute' is another common word for 7 #'instance variable'. 8 9 10 #Write your class here! 11 12 13 14 #Below are some lines of code that will test your function. 15 #You can change the value of the variable(s) to test your 16 #function with different inputs. 17 # 18 #If your function works correctly, this will originally 19 #print 128 and red, each on a separate line. 20 new_phone = Phone() 21 print (new_phone.storage) 22 print (new_phone.color) 23 24 25 Submit Run Grades Reset Console output will be displayed here 5.1.2 Coding Exercise 2 (External resource) (3.0 points possible) Number.py 1 # Write a class named "Number" with one attribute called 2 #"value" which defaults to 0 and another attribute called 3 #"even" which defaults to True. 4 5 #Next, create an instance of this class and assign it to 6 #a variable called "number_instance". 7 # # 8 #Then, set the value attribute to 101 and the even 9 #attribute to False. 10 11 12 #Write your code here! 13 14 15 #Note that this exercise does not print anything by 16 #default. You're welcome to add print statements to debug 17 #your code when running it. Note that the autograder 18 #will check both your value for number_instance and your 19 #definition of the class Number. 20 21 22 Submit Run Grades Reset Console output will be displayed here 5.1.4 Coding Exercise 1 (External resource) (3.0 points possible) Number.py 1 #Rewrite the "Number" class from 5.1.2 Coding Exercise 2. 2 # This time, however, require arguments for value and 3 #even in the constructor. Then, inside the constructor, 4 #create new instance variables called value and even that 5 #copy the values of the arguments passed into the 6 #constructor. 7 # 8 # In other words, rewrite the Number class such that value 9 # and even behave the way studentName and enrolled behaved 10 # in the exercise above, and the way firstname and lastname 11 # behaved in video 5.1.4.1. 12 # 13 #Then, as before, create an instance of this class and 14 # assign it to a variable called "number_instance". value 15 # should again be set to 101 and even should be set to 16 #False. 17 # 18 #Hint: Remember, the way you initialize the instance will 19 # have to change, too, based on the changes to the 20 #constructor that we're requiring. 21 23 # Write your code here! 24 25 26 #Note that this exercise does not print anything by 27 #default. You're welcome to add print statements to debug 28 #your code when running it. Note that the autograder 29 #will check both your value for number_instance and your 30 #definition of the class Number. 31 33 Submit Run Grades Reset Console output will be displayed here 5.1.2 Coding Exercise 1 (External resource) (3.0 points possible) Phone.py 1 # Write a class named "Phone". The Phone class should 2 #have an attribute called "storage" which defaults to 3 #128, and an attribute called "color" which defaults 4 #to "red". 5 # 6 #Hint: 'attribute' is another common word for 7 #'instance variable'. 8 9 10 #Write your class here! 11 12 13 14 #Below are some lines of code that will test your function. 15 #You can change the value of the variable(s) to test your 16 #function with different inputs. 17 # 18 #If your function works correctly, this will originally 19 #print 128 and red, each on a separate line. 20 new_phone = Phone() 21 print (new_phone.storage) 22 print (new_phone.color) 23 24 25 Submit Run Grades Reset Console output will be displayed here 5.1.2 Coding Exercise 2 (External resource) (3.0 points possible) Number.py 1 # Write a class named "Number" with one attribute called 2 #"value" which defaults to 0 and another attribute called 3 #"even" which defaults to True. 4 5 #Next, create an instance of this class and assign it to 6 #a variable called "number_instance". 7 # # 8 #Then, set the value attribute to 101 and the even 9 #attribute to False. 10 11 12 #Write your code here! 13 14 15 #Note that this exercise does not print anything by 16 #default. You're welcome to add print statements to debug 17 #your code when running it. Note that the autograder 18 #will check both your value for number_instance and your 19 #definition of the class Number. 20 21 22 Submit Run Grades Reset Console output will be displayed here 5.1.4 Coding Exercise 1 (External resource) (3.0 points possible) Number.py 1 #Rewrite the "Number" class from 5.1.2 Coding Exercise 2. 2 # This time, however, require arguments for value and 3 #even in the constructor. Then, inside the constructor, 4 #create new instance variables called value and even that 5 #copy the values of the arguments passed into the 6 #constructor. 7 # 8 # In other words, rewrite the Number class such that value 9 # and even behave the way studentName and enrolled behaved 10 # in the exercise above, and the way firstname and lastname 11 # behaved in video 5.1.4.1. 12 # 13 #Then, as before, create an instance of this class and 14 # assign it to a variable called "number_instance". value 15 # should again be set to 101 and even should be set to 16 #False. 17 # 18 #Hint: Remember, the way you initialize the instance will 19 # have to change, too, based on the changes to the 20 #constructor that we're requiring. 21 23 # Write your code here! 24 25 26 #Note that this exercise does not print anything by 27 #default. You're welcome to add print statements to debug 28 #your code when running it. Note that the autograder 29 #will check both your value for number_instance and your 30 #definition of the class Number. 31 33 Submit Run Grades Reset Console output will be displayed here
Expert Answer:
Answer rating: 100% (QA)
Find the python codes below 512 Phonepy class Phone def initself selfstorage 128 s... View the full answer
Related Book For
Business Statistics in Practice
ISBN: 978-0077404741
6th edition
Authors: Bruce Bowerman, Richard O'Connell
Posted Date:
Students also viewed these computer network questions
-
1. Write a class called Student. This student class should have the following fields: Id: This is the Id of the student. -_scores: This is a list of scores that belong to the student. Add the...
-
Create a class called Heater, that contains four fields, temperature, increment, max and min, all of whose type is double. Make sure you write a description of your new Class in the comments, with...
-
In this exercise we consider how to deal with class lengths that are unequal (and with open-ended classes) when setting up histograms. Often data are published in this form and we wish to construct a...
-
The Apache NetBeans IDE is mainly composed of NetBeans Open-Source IDE and NetBeans Platform. (True/False)
-
In the documentary movie, Expelled: No Intelligence Allowed, there was a 15-second clip of "Imagine," a song by John Lennon. The purpose of the scene was to criticize the song's message. His wife and...
-
In Fig P2.33 the pressure at point A is 25 psi. All fluids are at 20ーC. What is the air pressure in the closed chamber B? SAE 30 oil 3 cm SG-145 5 cm 8 cm 3 cm Water
-
Respondents Varsity Brands, Inc., Varsity Spirit Corporation, and Varsity Spirit Fashions & Supplies, Inc., design, make, and sell cheerleading uniforms. Respondents have obtained or acquired more...
-
In 2010, Bailey Corporation discovered that equipment purchased on January 1, 2008, for $50,000 was expensed at that time. The equipment should have been depreciated over 5 years, with no salvage...
-
3. A bag of mixed nuts contains almonds and hazelnuts. There are (6x+13) nuts in this particular bag, and (3x-7) of these are hazelnuts. Which expression represents the number of almonds in the bag?...
-
Pam Corporation purchased 75 percent of the outstanding voting stock of Sun Corporation for $4,800,000 on January 1, 2016. Sun's stockholders' equity on this date consisted of the following (in...
-
Calculate the amount of payroll tax due and an effective tax rate, correct to the nearest hundredth of a percent. Calculating four taxes: Social Security, Medicare,Federal income, and New York state.
-
What kinds of policies has the U.S. government pursued to encourage home ownership, and how do they achieve this goal?
-
What is Tobins q? How does it provide a theory of investment spending?
-
Why does structural unemployment occur?
-
What are the arguments for and against rules?
-
According to the Federal Reserve Act of 1913 (Section 13.3), In unusual and exigent circumstances, the Board of Governors of the Federal Reserve System, [] may authorize any Federal Reserve bank,...
-
Consider the following code: void loop() } . if (digitalRead(tiltSensorPin)) { // check if the pin is high digitalWrite(firstLEDPin, HIGH);// if it is high turn on firstLED digitalWrite( second...
-
The Pletcher Transportation Company uses a responsibility reporting system to measure the performance of its three investment centers: Planes, Taxis, and Limos. Segment performance is measured using...
-
Set up probability revision tables to a. Find the probability that the "economist says up" and rind the posterior probabilities of market up. market flat, and market down given that the "economist...
-
Consider Exercise 4.14 (page 170). Using the results in Table 4.4 (page 171), estimate the probability that a randomly selected 21- to 49-year-old consumer would a. Give the phrase a rating of 4 or 5...
-
a. Construct a relative frequency distribution and a percent frequency distribution for the bottle design ratings. b. Construct a cumulative frequency distribution and a cumulative percent frequency...
-
Find the frequency response of the given system. \(4 \ddot{x}+12 \dot{x}+13 x=40 \sin \left(\frac{1}{3} t ight)\)
-
A second-order dynamic system is modeled as \[4 \ddot{x}+4 \dot{x}+5 x=0, \quad x(0)=0.4, \dot{x}(0)=0\] a. Find the free response \(x(t)\). b. \(A\) Plot the free response by using the initial...
-
Plot the specified output by using the RK4 method. \(4 \ddot{x}+3 \dot{x}+2 x|x|=\frac{1}{2}+\sin t, \quad x(0)=1, \quad \dot{x}(0)=-1, \quad 0 \leq t \leq 15\), output : \(x\)
Study smarter with the SolutionInn App