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]
3 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]3 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
Describe shortly about the following Linux directories and theirpurpose,1. lib2. etc3. Boot4. Root5. home
Bingel [31]

Answer:

 Linux directories and their purposes are:

1) lib - Lib file contained the share object library file which necessary to boots system and this directory contain file module stored in the kernel.

2) etc - etc file is the configuration file that they are local in the machines. When the program run these file are stored in the directories. this can be static and do not executable directory.

3) Boot - Boot file are stored in the directory which required processing of linux boot and such files are included in the linux kernel of the file.

4) Root - Root file are the best user root directory and user cannot view this directories from there account. This file usually contain administrative file system.  

5) Home - Home file contained the user directory and it is the default system of linux. Home directory helps user to enable any network system to access there home directories.

5 0
3 years ago
Java allows small programs, called _____, to be embedded with an Hypertext Markup Language (HTML) document.
aleksandr82 [10.1K]

Answer:Applets

Explanation: In java,applets are the small programs that create the interactivity with the user in a particular application of the web. It is used for apart from the usage of the Hyper text mark-up language(HTML) because it adds-on the interactive feature towards the user , which are absent in the HTML.It helps in the handling.of the control buttons of device like mouse.

3 0
3 years ago
What is a characteristic ofa good cloud-based hosting?
Aliun [14]

Answer:

Explanation:

A good cloud-based hosting has many beneficial characteristics, some of which include on-demand self-service, broad network access, and being very elastic and scalable. These characteristics allow for a large number of users to benefit from the service at any time of the day and at a very fast speed due to the broad network access.

6 0
3 years ago
Each of the following code fragments contains a number of security vulnerabilities. For each fragment, identify these security v
Trava [24]

Answer:

Check the explanation

Explanation:

a)

1) int main(int argc, char *argv){

argv has always been an array of pointer whereby each and every element points to the command line argument that is passed to the program.

int main(int argc, char *argv[]) {

2) passwords = fopen(filePath, "r");

argv[0] always holds the name of the program currently running i.e. itself

So you shouldn't even try not to open a executable file for reading. since doing this will not give error but you won't be able to read the file as it is a binary file.

it is god to always check whether the file was opened successfully or not after opening the file. If file was not opened successfully fopen will return NULL.

passwords = fopen(filePath, "r");

if(passwords == NULL)

{

printf(“\n Unable to open file”);

return -1;

}

3) execl(shellPath, "shell", NULL);

Before making a call to execl you should close the open file

close(passwords);

b)

1) char itemID[9];

After creating a char array one should always initialize the array as it may contain some garbage value.

char itemID[9] = “”;

2) scanf("%d", &unitsOrdered);

Since unitOrdered represents the quantity, it should always be non zero and non negative

c)

1) char fullName[MAX_LEN];

MAX_LEN should not be zero or negative as it used to define the size.

If ( MAX_LEN <=0 )

{

return error;

}

else

{

char fullName[MAX_LEN]

}

2) strcpy(fullName, firstName);

Before using the string functions you're expected to always make sure that the pointer that you are passing to the functions should not be NULL i.e. the pointers should always pass to certain memory location.

if (firstName && lastName)

{

strcpy(fullName, firstName);

strcat(fullName, " ");

strcat(fullName, lastName);

return fullName;

}

else

{

return error;

}

5 0
3 years ago
What is the total resistance in a circuit that contains three 60 ohm resistors connected in a series?
nignag [31]
I think it is D 180
5 0
4 years ago
Read 2 more answers
Other questions:
  • Brendan is examining a report using the Design view. Which section in the Design view is going to appear only once on the first
    13·1 answer
  • What does the key combination ctrl+s achieve?
    7·2 answers
  • A(n) ____ is a named collection of data that exists on a storage medium.
    7·1 answer
  • I need help making this table in html code I have some of chart done but idk where to go after the 6:30pm part
    13·1 answer
  • I need help RIGHT NOW!!!!!!!!!!!!!!!!
    6·1 answer
  • The operating system, and in particular the scheduler, is not an important component of a real-time system.
    14·1 answer
  • When adding shapes to a presentation, the outline can be one color, and the fill must be the exact same color.
    12·2 answers
  • The method "someOtherMethod" is NOT defined as static. This means...
    5·1 answer
  • How was the Big Ben project similar to the investigation you conducted in class to determine if the table was vibrating? How is
    7·1 answer
  • Analyze the sentence below . choose your answer on the box below write your answer in your quiz notebook
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!