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
krok68 [10]
2 years ago
10

Problem: Write the Python code of a program called ComputeSquare that asks the user to enter the length of the side of the squar

e and displays the area and perimeter of the square. Check that the side length is greater than zero, and if it is not, display an informative error message to the user. ​
Computers and Technology
1 answer:
Lera25 [3.4K]2 years ago
6 0
<h2>Solution :</h2>

The given problem is solved in Python.

def ComputeSquare():

side = float(input('Enter the side of the square: '))

if side > 0:

perimeter = 4 * side

area = side * side

print('Perimeter of the square is:',

perimeter, 'unit.')

print('Area of the square is:', area, 'square unit.')

<h3> else:</h3>

print('Invalid input.')

ComputeSquare()

<h2>Explanation :-</h2>

  • In this program, we create a function ComputeSquare() to calculate the perimeter and area of a square.

  • The function asks the user to enter the side of the square. The side is then stored in a variable.

  • Now, we check whether the side is greater than 0 or not using if-else statement.

  • If the condition is true, the perimeter and area is calculated which is displayed using print() statement.

  • If the condition is false, the else blocks executes printing the error message.

<h3>Refer to the attachment for output.</h3>

You might be interested in
C++
Luden [163]

Answer:

The program to this question as follows:

Program:

//header file iostream

#include<iostream> //including file for use basic function

//using name space

using namespace std;

//main method

int main() //defining main method

{

   int a[3][3]; //defining two dimension array

   int x,y,sum=0; //defining variables

   cout<<"Enter array elements: "<<endl; //message

   for(x=0;x<3;x++) // for row

   {

       for(y=0;y<3;y++) //for column

       {

          cin>>a[x][y]; //input values from user.

       }

       

   }

   //loop for calculting sum.

   for(x=0;x<3;x++)

   {

       for(y=0;y<3;y++)

       {

       sum=sum+a[x][y];//add all elements

       }

       

   }

   cout<<"Sum: "<<sum; //print sum.

   return 0;

}

Output:

Enter array elements:  

1

2

3

4

5

6

7

8

9

Sum: 45

Explanation:

In the above C++ programming language code first, a header file is included then the main method is declared, inside a main method 2D array that is "a[][]", and an integer variable is defined that are "i, j, and sum". In the next line for loop is used, this loop is used two times that can be described as follows:

  • The first time it is used for inserting elements from user ends.  
  • The second time, it uses the sum variable to add all array elements. and in the last print function that is "cout" is used for print sum variable value.
7 0
3 years ago
What are the odds that you find someone you know in person on here
jenyasd209 [6]

Answer:

0

Explanation:

As far as I know, no one I know, even knows that brainly exists. Those who do  know about it don't use it.

6 0
2 years ago
Which of the following is not a use of a hash function
soldi70 [24.7K]

Answer:

the answer would be there

Explanation:

7 0
2 years ago
How might a company gain followers on Twitter?
Tresset [83]
By sending persuasive / informable and interesting posts to gain followers.
3 0
3 years ago
What do you mean by algorithm​
Snowcat [4.5K]

A process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer.

7 0
3 years ago
Read 2 more answers
Other questions:
  • Just forgot where she saved a certain file on her computer therefore she searched for all files with jpg file extension which ty
    13·2 answers
  • Almost immediately after a server migration project, employees are complaining that they can't reach the Internet. You sit down
    8·1 answer
  • How do you copy and paste plz let me know
    14·2 answers
  • How does cryptocurrency exchange software works?
    14·1 answer
  • What does the top level domain in a url inducate? A. The organization or company that owns the website. B. The organization or c
    6·2 answers
  • EASY What does the Backspace key do?
    6·1 answer
  • What is the Cycle of Dependency?
    14·1 answer
  • These 2 questions PLEASEEE (:
    14·1 answer
  • Writing queries in sql to compile data from a database is related to the physical level of databases true or false?.
    10·1 answer
  • What type of an attack is being executed if an attacker substituted an invalid mac address for the network gateway so no users c
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!