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:...
Write a program in Python jupyter notebook for following: Part1: Course grade calculation: Course grades for...
Write a program in Python jupyter notebook for following: Part1: Course grade calculation: Course grades for CIS 1100 are calculated based on two assignments, a midterm exam, and a final exam. Here are the weights of these. Assignments 25% Midterm exam 35% Final exam 40% Ask the user for the scores they received for the two assignments, midterm exam, and the final exam. Then calculate and display their total weighted score they received for the course. Based on the weighted...
What is the python code to solve this type of nonlinear equation in jupyter notebook 16cos2x+16sin2x-40.1cosx+2.3sinx+16.223=0...
What is the python code to solve this type of nonlinear equation in jupyter notebook 16cos2x+16sin2x-40.1cosx+2.3sinx+16.223=0 Please show the code clearly.
Please give me an example of how we import stock data in jupyter notebook(Python) and analyze...
Please give me an example of how we import stock data in jupyter notebook(Python) and analyze each step.
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;    }...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT