Table of Contents

Calculate the Cost of a Tent – User defined Func

Example Description
Python program to compute tent cost with cylindrical and conical parts. Calculates total canvas area and final payable amount including tax.

Introduction:

This Python program calculates the cost of a tent using the dimensions of its cylindrical and conical parts. The program prompts the user to enter the height and radius of the cylindrical part, as well as the slant height of the conical part. It then calculates the total canvas area and the total cost of the canvas before tax. Finally, it calculates the final amount payable, including tax.

Code:

#Program to calculate the cost of tent
#function definition 
def cyl(h,r):
 area_cyl = 2*3.14*r*h #Area of cylindrical part
 return(area_cyl)
#function definition
def con(l,r):
 area_con = 3.14*r*l #Area of conical part
 return(area_con)
#function definition
def post_tax_price(cost): #compute payable amount for the tent
 tax = 0.18 * cost;
 net_price = cost + tax
 return(net_price)
print("Enter values of cylindrical part of the tent in meters:")
h = float(input("Height: "))
r = float(input("Radius: "))
csa_cyl = cyl(h,r) #function call 
l = float(input("Enter slant height of the conical area in meters: "))
csa_con = con(l,r) #function call
#Calculate area of the canvas used for making the tent
canvas_area = csa_cyl + csa_con
print("Area of canvas = ",canvas_area," m^2")
#Calculate cost of canvas
unit_price = float(input("Enter cost of 1 m^2 canvas in rupees: "))
total_cost = unit_price * canvas_area
print("Total cost of canvas before tax = ",total_cost)
print("Net amount payable (including tax) = ",post_tax_price(total_cost))

Logic:

The program uses three functions: cyl() calculates the area of the cylindrical part, con() calculates the area of the conical part, and post_tax_price() computes the final amount payable including tax. The program takes user input for the dimensions and cost of the canvas. It then calls the functions and performs the necessary calculations to output the canvas area, the total cost before tax, and the final amount payable including tax.

Output:

>> Enter values of cylindrical part of the tent in meters:

Height: 5
Radius: 2
Enter slant height of the conical area in meters: 3
>> Area of canvas = 81.64 m^2

Enter cost of 1 m^2 canvas in rupees: 50
>> Total cost of canvas before tax = 4082.0

>> Net amount payable (including tax) = 4816.76