1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Reika [66]
3 years ago
10

Create a geometry application For this exercise you will create a module named ‘shapes.py’ and a program that uses it. The modul

e will contain two classes: Circle and Rectangle. • Start with the class example (Module 10, part 1b) as a basis for Circle o Add an attribute and getter method for the perimeter (distance around the outside, officially called the circumference ). • Write a class named Rectangle to represent a rectangle. The class should contain: o Two attributes that specify the length and the width. These should initially be set when the object is created with __init__. o Setter and getter methods for length and width. o Attributes and getter methods for the area and the perimeter. Then write a main program that will use the module.
Computers and Technology
1 answer:
Maurinko [17]3 years ago
7 0

Answer:

See explaination

Explanation:

# shapes.py

import math class Circle: def __init__(self, radius = 0): self.__radius = radius self.__area = math.pi * self.__radius ** 2 self.__circumference = 2 * math.pi * self.__radius def set_radius(self, radius): self.__radius = radius self.__area = math.pi * self.__radius ** 2 self.__circumference = 2 * math.pi * self.__radius def get_radius(self): return self.__radius def get_area(self): return self.__area def get_circumference(self): return self.__circumference class Rectangle: def __init__(self, length = 0, breadth = 0): self.__length = length self.__breadth = breadth self.__calc_area() self.__calc_perimeter() def __calc_area(self): self.__area = self.__length * self.__breadth def __calc_perimeter(self): self.__perimeter = 2 * (self.__length + self.__breadth) def set_length(self, length): self.__length = length self.__calc_area() self.__calc_perimeter() def set_breadth(self, breadth): self.__breadth = breadth self.__calc_area() self.__calc_perimeter() def get_length(self): return self.__length def get_breadth(self): return self.__breadth def get_area(self): return self.__area def get_perimeter(self): return self.__perimeter

# testShapes.py (Main program)

import shapes if __name__ == "__main__": print("a. Circle") print("b. Rectangle") choice = input("\nChoose a Shape to continue: ") if choice == "a": radius = int(input("\nEnter Radius of the Circle: ")) myCircle = shapes.Circle(radius) print("\nArea of Circle:", myCircle.get_area()) print("Circumference of Circle:", myCircle.get_circumference()) reset = input("Do you want to change Radius (y/n): ") if reset == "y" or reset == "Y": radius = int(input("\nEnter new Radius of the Circle: ")) myCircle = shapes.Circle(radius) print("\nArea of Circle:", myCircle.get_area()) print("Circumference of Circle:", myCircle.get_circumference()) elif choice == "b": length = int(input("\nEnter length of Rectangle: ")) breadth = int(input("Enter breadth of Rectangle: ")) myRectangle = shapes.Rectangle(length, breadth) print("\nArea of Rectangle:", myRectangle.get_area()) print("Perimeter of Rectangle:", myRectangle.get_perimeter()) reset = input("Do you want to change Length and Breadth (y/n): ") if reset == "y" or reset == "Y": length = int(input("\nEnter new length of Rectangle: ")) breadth = int(input("Enter new breadth of Rectangle: ")) myRectangle = shapes.Rectangle(length, breadth) print("\nArea of Rectangle:", myRectangle.get_area()) print("Perimeter of Rectangle:", myRectangle.get_perimeter()) else: print("Invalid choice!!! \'", choice, "\'\nExiting...")

You might be interested in
Complete function PrintPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 3, print "To
SVETLANKA909090 [29]

Answer:

<h2>Function 1:</h2>

#include <stdio.h> //for using input output functions

// start of the function PrintPopcornTime body having integer variable //bagOunces as parameter

void PrintPopcornTime(int bagOunces){

if (bagOunces < 3){ //if value of bagOunces is less than 3

 printf("Too small"); //displays Too small message in output

 printf("\n"); } //prints a new line

//the following else if part will execute when the above IF condition evaluates to //false and the value of bagOunces is greater than 10

else if (bagOunces > 10){

    printf("Too large"); //displays the message:  Too large in output

    printf("\n"); //prints a new line }

/*the following else  part will execute when the above If and else if conditions evaluate to false and the value of bagOunces is neither less than 3 nor greater than 10 */

else {

/* The following three commented statements can be used to store the value of bagOunces * 6 into result variable and then print statement to print the value of result. The other option is to use one print statement printf("%d",bagOunces * 6) instead */

    //int result;

    //result = bagOunces * 6;

    //printf("%d",result);

 printf("%d",bagOunces * 6);  /multiplies value of bagOunces  to 6

 printf(" seconds");

// seconds is followed with the value of bagOunces * 6

 printf("\n"); }} //prints a new line

int main(){ //start of main() function body

int userOunces; //declares integer variable userOunces

scanf("%d", &userOunces); //reads input value of userOunces

PrintPopcornTime(userOunces);

//calls PrintPopcornTime function passing the value in userOunces

return 0; }

Explanation:

<h2>Function 2:  </h2>

#include <stdio.h> //header file to use input output functions

// start of the function PrintShampooInstructions body having integer variable numCycles as parameter

void PrintShampooInstructions(int numCycles){

if(numCycles < 1){

//if conditions checks value of numCycles is less than 1 or not

printf("Too few."); //prints Too few in output if the above condition is true

printf("\n"); } //prints a new line

//else if part is executed when the if condition is false and else if  checks //value of numCycles is greater than 4 or not

else if(numCycles > 4){

//prints Too many in output if the above condition is true

printf("Too many.");

printf("\n"); } //prints a new line

//else part is executed when the if and else if conditions are false

else{

//prints "N: Lather and rinse." numCycles times, where N is the cycle //number, followed by Done

for(int N = 1; N <= numCycles; N++){

printf("%d",N);

printf(": Lather and rinse. \n");}

printf("Done.");

printf("\n");} }

int main() //start of the main() function body

{    int userCycles; //declares integer variable userCycles

   scanf("%d", &userCycles); //reads the input value into userCycles

   PrintShampooInstructions(userCycles);

//calls PrintShampooInstructions function passing the value in userCycles

   return 0;}

I will explain the for loop used in PrintShampooInstructions() function. The loop has a variableN  which is initialized to 1. The loop checks if the value of N is less than or equal to the value of numCycles. Lets say the value of numCycles = 2. So the condition evaluates to true as N<numCycles  which means 1<2. So the program control enters the body of loop. The loop body has following statements. printf("%d",N); prints the value of N followed by

printf(": Lather and rinse. \n"); which is followed by printf("Done.");

So at first iteration:

printf("%d",N); prints 1 as the value of N is 1

printf(": Lather and rinse. \n");  prints : Lather and rinse and prints a new line \n.

As a whole this line is printed on the screen:

1: Lather and rinse.

Then the value of N is incremented by 1. So N becomes 2 i.e. N = 2.

Now at second iteration:

The loop checks if the value of N is less than or equal to the value of numCycles. We know that the value of numCycles = 2. So the condition evaluates to true as N<numCycles  which means 2=2. So the program control enters the body of loop.

printf("Done."); prints Done after the above two lines.

printf("%d",N); prints 2 as the value of N is 2

printf(": Lather and rinse. \n");  prints : Lather and rinse and prints a new line \n.

As a whole this line is printed on the screen:

2: Lather and rinse.

Then the value of N is incremented by 1. So N becomes 2 i.e. N = 3.

The loop again checks if the value of N is less than or equal to the value of numCycles. We know that the value of numCycles = 2. So the condition evaluates to false as N<numCycles  which means 3>2. So the loop breaks.

Now the next statement is:

printf("Done."); which prints Done on the screen.

So as a whole the following output is displayed on the screen:

1: Lather and rinse.

2: Lather and rinse.

Done.

The programs along with their outputs are attached.

6 0
3 years ago
A write the result P*=++j where j is 24
MariettaO [177]

Answer:

ang hrap nmn nyan

Explanation:

poede po

7 0
2 years ago
You receive an email that appears to legitimately be from your Bank. The email indicates the need for verification of your infor
anzhelika [568]

Answer:

phishing

Explanation:

6 0
2 years ago
Read 2 more answers
My laptop volume has got really low all of a sudden. It wasn't the best to start with but now i can barely even hear it at 100%.
nadezda [96]

Answer:

make sure the speaker is clean and you volume setting is on normal there is alot of setting for deaf people so make sure that is correctly

4 0
2 years ago
"what do you perform when you want to recall specific records from a database"
Ivan
A select query


select column1, column2, columnN
from table
where condition
order to be pretty;
5 0
2 years ago
Other questions:
  • Because public key encryption requires the use of two different keys, it is also known as _____ encryption
    13·1 answer
  • Which of the following is used to encrypt web application data?
    11·1 answer
  • The basic work area of the computer is it screen that you when you first fire up your computer
    6·1 answer
  • Which are two main areas of the properties inspector
    7·1 answer
  • ---------------is a systematic review of a person’swork and achievements over a recent period, usually leading toplans for the f
    11·1 answer
  • 17. When an industrial electrical circuit requires a 220 VAC single phase power supply, the electric power supply circuit is nor
    7·1 answer
  • Can someone please type a code that makes a house in python and turtle graphics i need help
    9·1 answer
  • How can a user access the Mailbox Cleanup tools?
    11·2 answers
  • Which is the highest level of the hierarchy of needs model?
    14·1 answer
  • What is text formatting?​
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!