0% found this document useful (0 votes)
110 views3 pages

CIS 100 - Introduction To Computer Science: Homework Assignment 4

This homework assignment involves writing a program to calculate and display the areas of various geometric shapes like triangles, squares, circles, etc. by defining separate functions for each shape's area calculation in a module file called "areas.py" and calling these functions in the main program. The program prompts the user to select a shape and enter the required inputs to calculate its area, importing the shape area functions from the module file to output the result.

Uploaded by

Jersey Phillips
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views3 pages

CIS 100 - Introduction To Computer Science: Homework Assignment 4

This homework assignment involves writing a program to calculate and display the areas of various geometric shapes like triangles, squares, circles, etc. by defining separate functions for each shape's area calculation in a module file called "areas.py" and calling these functions in the main program. The program prompts the user to select a shape and enter the required inputs to calculate its area, importing the shape area functions from the module file to output the result.

Uploaded by

Jersey Phillips
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Homework Assignment 4

CIS 100 – Introduction to Computer Science


Due Date: 03-29-2021, 11: 59 pm Points: 8

Instructions:
 Submit your assignments in word to the blackboard.
 The format of the output should be same as specified in the sample output
 Input to every program is colored in blue and output is in green
Programs

1. Write a program to calculate and display the area of various shapes (Triangle, Square,
Rectangle, Parallelogram, Trapezoid, Circle, Ellipse and Sector). The program should first
display various choices of shapes and then prompt the user to enter the choice of a
shape. Based on the choice, the program should again prompt the user to enter
required inputs to calculate the area of a chosen shape.
This program should define separate functions for each shape in a module file
“areas.py” to calculate area of shapes. These functions have to be called in main
program. (8 points)

Sample “areas.py” module file


def square(side):
statements
return result

def triangle(b,h):
statements
return result

Refer this link for the area calculations: https://www.mathsisfun.com/area.html

Sample Output:
Triangle – T
Square – S
Rectangle – R
Parallelogram – P
Trapezoid – Z
Circle – C
Ellipse – E
Sector – O
Enter the choice of a shape: R
Enter the width: 5
Enter the height: 3
Area is 15

CODE:
Module file code:
def triangle(b, h):
return (1/2) * b * h
def square(side):
return side * side
def rectangle(b, h):
return b * h
def parallelogram(b, h):
return b * h
def trapezoid(b1, b2, h):
return (1/2) * (b1 * b2) * h
def circle(r):
return 3.14159 * r * r
def ellipse(b, h) :
return 3.14159 * b * h
def sector(r, a):
return (1/2) * r * r * a
Main program file code:
print("Triangle-T")
print("Square-S")
print("Rectangle-R")
print("Parallelogram-P")
print("Trapezoid-Z")
print("Circle-C")
print("Ellipse-E")
print("Sector-O")
shape = input("Enter a choice of shape:")

import areas
if shape == "T":
b = float(input("Enter base value:"))
h = float(input("Enter height value:"))
print("The area is", areas.triangle(b,h))

elif shape == "S":


side = float(input("Enter side value:"))
print("The area is", areas.square(side))

elif shape == "R":


b = float(input("Enter base value:"))
h = float(input("Enter height value:"))
print("The area is", areas.rectangle(b,h))

elif shape == "P":


b = float(input("Enter base value:"))
h = float(input("Enter height value:"))
print("The area is", areas.parallelogram(b,h))

elif shape == "Z":


b1 = float(input("Enter one width value value:"))
b2 = float(input("Enter second width value:"))
h = float(input("Enter height value:"))
print("The area is", areas.trapezoid(b1,b2,h))

elif shape == "C":


r = float(input("Enter radius value:"))
print("The area is", areas.circle(r))

elif shape == "E":


b = float(input("Enter base value:"))
h = float(input("Enter height value:"))
print("The area is", areas.ellipse(b,h))

elif shape == "O":


r = float(input("Enter base value:"))
a = float(input("Enter height value:"))
print("The area is", areas.sector(r,a))

OUTPUT:

You might also like