Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

program to print areas in python

# define a function for calculating
# the area of a shapes
def calculate_area(name):
   
  # converting all characters
  # into lower cases
  name = name.lower()
   
  # check for the conditions
  if name == "rectangle":
    l = int(input("Enter rectangle's length: "))
    b = int(input("Enter rectangle's breadth: "))
     
    # calculate area of rectangle
    rect_area = l * b
    print(f"The area of rectangle is
          {rect_area}.")
   
  elif name == "square":
    s = int(input("Enter square's side length: "))
       
    # calculate area of square
    sqt_area = s * s
    print(f"The area of square is
          {sqt_area}.")
 
  elif name == "triangle":
    h = int(input("Enter triangle's height length: "))
    b = int(input("Enter triangle's breadth length: "))
       
    # calculate area of triangle
    tri_area = 0.5 * b * h
    print(f"The area of triangle is
          {tri_area}.")
 
  elif name == "circle":
    r = int(input("Enter circle's radius length: "))
    pi = 3.14
         
    # calculate area of circle
    circ_area = pi * r * r
    print(f"The area of circle is
          {circ_area}.")
         
  elif name == 'parallelogram':
    b = int(input("Enter parallelogram's base length: "))
    h = int(input("Enter parallelogram's height length: "))
     
    # calculate area of parallelogram
    para_area = b * h
    print(f"The area of parallelogram is
          {para_area}.")
     
  else:
    print("Sorry! This shape is not available")
 
# driver code
if __name__ == "__main__" :
   
  print("Calculate Shape Area")
  shape_name = input("Enter the name of shape whose area you want to find: ")
   
  # function calling
  calculate_area(shape_name)
Comment

PREVIOUS NEXT
Code Example
Python :: How to join or combine multiple csv files with concatenate and export dataframe to csv format 
Python :: how to extends page in django 
Python :: yml file for django 
Python :: python yield async awiat 
Python :: gensim loop keyed vector 
Python :: check true false in python 
Python :: python csv file plot column 
Python :: python zeep- SOAP protocol -WSDL/XSD?XML 
Python :: django url wildcard 
Python :: Reading CSV delimited format 
Python :: python http server onliner 
Python :: enumerate count 
Python :: 10 minutes to pandas 
Python :: emi calculator python code 
Python :: what is self in python constructor 
Python :: python Access both key and value without using items() 
Python :: how to reorder columns in pandas 
Python :: how to save the command result with ! in python 
Python :: signup generic 
Python :: una esfera solida de radio 40 cm tiene una carga positiva 
Python :: python scrape data from aspx page 
Python :: gym for creating simple grid world 
Python :: How to send data to scrapy pipeline to mongodb 
Python :: pyqt message box set information text 
Python :: more args python 
Python :: Python of if...else 
Python :: python empty list boolean 
Python :: no repetir elementos en una lista python 
Python :: django register form return a 302 request 
Python :: python synta error 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =