Assignment

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Name: Dennis Dave B.

Lamoste Section: BSCE 1-A

Christian C. Peralta

Assignment: Create a program that combines dictionary, tuples, and functions.

Code:

def calculate_area(shape, dimensions):


if shape == 'rectangle':

length, width = dimensions

area = length * width

elif shape == 'circle':

radius = dimensions[0]

area = 3.14 * radius**2

else:

area = None

print('Unsupported shape.')

return area

def print_shape_area(shape, dimensions):

area = calculate_area(shape, dimensions)

if area is not None:

print(f"The area of the {shape} is {area:.2f} units squared.")

shape_input = input("Enter the shape (rectangle or circle): ")

if shape_input not in ['rectangle', 'circle']:

print('Unsupported shape.')

else:

if shape_input == 'rectangle':

length_input = float(input("Enter the length: "))

width_input = float(input("Enter the width: "))

dimensions = (length_input, width_input)

else:
radius_input = float(input("Enter the radius: "))

dimensions = (radius_input,)

print_shape_area(shape_input, dimensions)

You might also like