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
Digiron [165]
3 years ago
12

Write a pyhton program to calculate area of a circle?

Computers and Technology
1 answer:
marta [7]3 years ago
8 0

Answer:

The code to calculate the area of a circle is:

from math import pi

def circleArea(radius):

 if radius > 0:

   return pi * (radius ** 2)

 else:

   return None

if __name__ == '__main__':

 radius = 5

 print("Radius: {} Area: {}".format(radius,circleArea(radius)))

Explanation:

A detailed explanation of each line of code is given below.

#Define the number pi used to calculate the area

from math import pi

#We define a function that calculates the area of a circle

def circleArea(radius):

#Check if the radius is valid ( radius > 0) since there aren´t negative radius

 if radius > 0:

#Compute the area formula for a circle \pi * radius^{2}

   return pi * (radius ** 2)

 else:

#Return None if the radius is invalid

   return None

#Run the function we´ve defined

if __name__ == '__main__':

#Define a radius

 radius = 5

#Call the function and parse the radius through it, then print the result

 print("Radius: {} Area: {}".format(radius,circleArea(radius)))

You might be interested in
In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program
solniwko [45]

Answer:

C code is given below

Explanation:

// Vigenere cipher

#include <ctype.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

/**

* Reading key file.

*/

char *readFile(char *fileName) {

   FILE *file = fopen(fileName, "r");

   char *code;

   size_t n = 0;

   int c;

   if (file == NULL) return NULL; //could not open file

   code = (char *)malloc(513);

   while ((c = fgetc(file)) != EOF) {

      if( !isalpha(c) )

          continue;

      if( isupper(c) )

          c = tolower(c);

      code[n++] = (char)c;

   }

   code[n] = '\0';

  fclose(file);

   return code;

}

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

   // Check if correct # of arguments given

   if (argc != 3) {

       printf("Wrong number of arguments. Please try again.\n");

       return 1;

   }

 

  // try to read the key file

  char *key = readFile(argv[1]);

  if( !key ) {

      printf( "Invalid file %s\n", argv[1] );

      return 1;

  }

 

  char *data = readFile(argv[2]);

  if( !data ) {

      printf("Invalid file %s\n", argv[2] );

      return 1;

  }

 

   // Store key as string and get length

   int kLen = strlen(key);

  int dataLen = strlen( data );

 

  printf("%s\n", key );

  printf("%s\n", data );

 

  int paddingLength = dataLen % kLen;

  if( kLen > dataLen ) {

      paddingLength = kLen - dataLen;

  }

  for( int i = 0; i < paddingLength && dataLen + paddingLength <= 512; i++ ) {

      data[ dataLen + i ] = 'x';

  }

 

  dataLen += paddingLength;

 

   // Loop through text

   for (int i = 0, j = 0, n = dataLen; i < n; i++) {          

       // Get key for this letter

       int letterKey = tolower(key[j % kLen]) - 'a';

     

       // Keep case of letter

       if (isupper(data[i])) {

           // Get modulo number and add to appropriate case

           printf("%c", 'A' + (data[i] - 'A' + letterKey) % 26);

         

           // Only increment j when used

           j++;

       }

       else if (islower(data[i])) {

           printf("%c", 'a' + (data[i] - 'a' + letterKey) % 26);

           j++;

       }

       else {

           // return unchanged

           printf("%c", data[i]);

       }

      if( (i+1) % 80 == 0 ) {

          printf("\n");

      }

   }

 

   printf("\n");

 

   return 0;

}

4 0
3 years ago
Read 2 more answers
Where is the start frame delimiter found in the Ethernet frame
Ksju [112]
Answer: The SFD is the eight-bit (one-byte) value that marks the end of the preamble, which is the first field of an Ethernet packet, and indicates the beginning of the Ethernet frame.
8 0
3 years ago
Select all that apply.
Leto [7]
You may do all of the given options.
Thank You!
8 0
4 years ago
I keep getting this error: postfix.cpp: In function ‘double RPN_evaluation(std::string)’: postfix.cpp:42:26: error: cannot conve
Svetradugi [14.3K]

Answer:

expr.at(g) returns a string, not a char. They are not the same thing and that is what the compiler is complaining about.

3 0
3 years ago
Drag the system component on the left to the device or program that fits with the system component.
Strike441 [17]

Answer:

A. Back up software - Utility software

B. Printer - Device drivers

C. Camera - Firmware

D. Television - Firmware

E. Games console - Firmware

F. Antivirus software - Utility software

G. Disk Cleaner - Utility software

H. Video Card - Device drivers

Explanation:

Computer system components are the physical or hardware and software parts of the device. It is a combination of system software like utility software, device drivers and firmware, application software, and the hardware components and kernel.

4 0
3 years ago
Other questions:
  • Please answer quick:))))
    7·1 answer
  • Briefly discuss constraints
    13·1 answer
  • What term identifies hard drives enclosed in a case other than your computer's case? A External hard drives B Flash drives C CD-
    8·2 answers
  • 1. Implement a method factorial(int n), that takes a number (int) and returns its factorial. Factorial of an integer is the prod
    13·1 answer
  • What term is used to describe the harassment of computer users through various forms of internet communications?
    5·1 answer
  • Ethan is a systems developer. He is working on a system where he will implement independent solutions for different processes. W
    14·1 answer
  • An expression involving byte, int, and literal numbers is promoted to which of these?
    12·1 answer
  • In general, font size for software-generated presentation slides should be no smaller than __________ points.
    8·1 answer
  • Question 3.3. Which of the following is NOT a computer protocol? FTP SMTP ISP TCP
    11·1 answer
  • When working with copper cabling (as opposed to fiber optic) a ________ can check a variety of a cable's electrical characterist
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!