Question

In: Computer Science

please solve using jupyter notebook . 10.9- (Square Class) Write a class that implements a Square...

please solve using jupyter notebook .

10.9- (Square Class) Write a class that implements a Square shape. The class should contain a side property. Provide an __init__ method that takes the side length as an argument. Also, provide the following read-only properties:

a) perimeter returns 4 × side.

b) area returns side × side.

c) diagonal returns the square root of the expression (2 × side2).

The perimeter, area and diagonal should not have corresponding data attributes; rather, they should use side in calculations that return the desired values. Create a Square object and display its side, perimeter, area and diagonal properties’ values.

Solutions

Expert Solution

10.9- (Square Class) Write a class that implements a Square shape. The class should contain a side property. Provide an __init__ method that takes the side length as an argument. Also, provide the following read-only properties:

a) perimeter returns 4 × side.

b) area returns side × side.

c) diagonal returns the square root of the expression (2 × side2).

The perimeter, area and diagonal should not have corresponding data attributes; rather, they should use side in calculations that return the desired values. Create a Square object and display its side, perimeter, area and diagonal properties' values


Explanation:

CODE IN PYTHON:

import math
class Square:
    def __init__(self, side):
        self.side = side
    def perimeter(self):
        return 4 * self.side
    def area(self):
        return self.side * self.side
    def diagonal(self):
        return math.sqrt(2 * self.side * self.side)

s =  Square(4)
print("Side of the square : " , s.side)
print("Perimeter of the square : " , s.perimeter())
print("Area of the square : " , s.area())
print("Diagonal of the square : {0:2f} ".format(s.diagonal()))

Output:

Side of the square: 4

Perimeter of the square : 16

Area of the square : 16

Diagonal of the square : 5.656854


Related Solutions

Please solve using jupyter notebook . 10.10- (Invoice Class) Create a class called Invoice that a...
Please solve using jupyter notebook . 10.10- (Invoice Class) Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as data attributes—a part number (a string), a part description (a string), a quantity of the item being purchased (an int) and a price per item (a Decimal). Your class should have an __init__ method that initializes the four data attributes....
Solve this Write a C++ class that implements a stack using a linked list. The type...
Solve this Write a C++ class that implements a stack using a linked list. The type of data contained in the stack should be double. The maximum size of the stack is 30. Implement the following methods: . · Constructor and destructor; // 5 pts · void push (double value); // pushes an element with the value into the stack. 5 pts. · double pop (); // pops an element from the stack and returns its value. 5 pts. ·...
using JUPYTER notebook: 9.1 (Class Average: Writing Grades to a Plain Text File) Figure 3.2 presented...
using JUPYTER notebook: 9.1 (Class Average: Writing Grades to a Plain Text File) Figure 3.2 presented a classaverage script in which you could enter any number of grades followed by a sentinel value, then calculate the class average. Another approach would be to read the grades from a file. In an IPython session, write code that enables you to store any number of grades into a grades.txt plain text file. In an IPython session, write code that reads the grades...
Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1,...
Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1, 2, 3, 5, 8, … 2. Check if a number is an Armstrong number A positive integer is called an Armstrong number of order n if abcd... = a^n + b^n + c^n + d^n + ... In case of an Armstrong number of 3 digits, the sum of cubes of each digits is equal to the number itself. For example: 153 = 1*1*1...
The purpose of this is to plot data using Matplotlib. Description complete the Jupyter notebook named...
The purpose of this is to plot data using Matplotlib. Description complete the Jupyter notebook named main.ipynb that reads in the file diamonds.csv into a Pandas DataFrame. Information about the file can be found here: ------- diamonds R Documentation Prices of over 50,000 round cut diamonds Description A dataset containing the prices and other attributes of almost 54,000 diamonds. The variables are as follows: Usage diamonds Format A data frame with 53940 rows and 10 variables: price price in US...
Focuses on the design, development, implementation, and testing of a Python program using Jupyter Notebook only...
Focuses on the design, development, implementation, and testing of a Python program using Jupyter Notebook only to solve the problem described below. You will write a program that simulates an Automatic Teller Machine (ATM). For this program, your code can have of user-defined functions only. However, the program must not call on any external functions or modules to handle any of the input, computational, and output requirements. Note, the program can be completed without the use of user-defined functions. Requirements:...
Please solve this problem in java. (simple linked list) public class MyLinkedList implements MiniList{ /* Private...
Please solve this problem in java. (simple linked list) public class MyLinkedList implements MiniList{ /* Private member variables that you need to declare: ** The head pointer ** The tail pointer */    private Node head;    private Node tail;       public class Node { // declare member variables (data and next)    Integer data;    Node next; // finish these constructors    public Node(int data, Node next) {               this.data=data;        this.next=next;    }...
Machine Learning do using python on jupyter notebook 1. Linear Regression Dataset used: Diabetes from sklearn...
Machine Learning do using python on jupyter notebook 1. Linear Regression Dataset used: Diabetes from sklearn You are asked to solve a regression problem in the Diabetes dataset. Please review the Diabetes dataset used before creating a program to decide which attributes will be used in the regression process. please use the cross-validation step to produce the best evaluation of the model. All you have to do is • Perform linear regression using the OLS (Ordinary Least Square) method (sklearn.linear_model.LinearRegression)...
A professor notices that more and more students are using their notebook computers in class, presumably...
A professor notices that more and more students are using their notebook computers in class, presumably to take notes. He wonders if this may actually improve academic success. To test this, the professor records the number of times each student uses his or her computer during a class for one semester and the final grade in the class (out of 100 points). If notebook computer use during class is related to improved academic success, then a positive correlation should be...
Write a program In python of Jupiter notebook (using loops) that prompts the user to enter...
Write a program In python of Jupiter notebook (using loops) that prompts the user to enter his/her favorite English saying, then counts the number of vowels in that (note that the user may type the saying using any combination of upper or lower case letters). Example: Enter your favorite English saying: Actions speak LOUDER than words. Number of wovels: 10
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT