Programs · Program 7-2
Q.Program 7-2: Program to calculate the payable amount for the tent using user defined functions.
Uttar Pradesh UpmspTextbookSubjective· 3mImportance★★★★★est
5% · 2/40 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Program 7-2 solves the same tent-billing problem as Program 7-1, but wraps each independent computation — cylinder surface, cone surface, GST — in its own user-defined function; the output is identical, the structure is far better.
The idea. This pair of programs is the textbook's demonstration of why functions exist: identical functionality, but each formula now lives in a named function with parameters and a return value. If tomorrow the tent gains a second cylindrical section, you call cyl_area() again instead of copying code.
# Program 7-2: payable amount for the tent (using user-defined functions)
def cyl_area(h, r):
"""Curved surface area of a cylinder."""
return 2 * 3.14 * r * h
def cone_area(l, r):
"""Curved surface area of a cone (l = slant height)."""
return 3.14 * r * l
def post_gst_price(cost):
"""Add 18% GST to the cost and return the payable amount."""
return cost + 0.18 * cost
# main program
h = float(input("Enter height of the cylindrical part (in m): "))
r = float(input("Enter radius of the tent (in m): "))
l = float(input("Enter slant height of the conical part (in m): "))
unit_price = float(input("Enter cost of 1 sq m of canvas (Rs.): "))
canvas_area = cyl_area(h, r) + cone_area(l, r)
print("Area of canvas needed:", round(canvas_area, 2), "sq m")
net_cost = canvas_area * unit_price
print("Cost of canvas : Rs.", round(net_cost, 2))
print("Payable amount (incl. 18% GST): Rs.", round(post_gst_price(net_cost), 2))
Key lines
- Each function takes exactly the values it needs as parameters and returns the result — no printing inside, so the functions stay reusable.
- The main program reads the inputs, composes the functions (
cyl_area(h, r) + cone_area(l, r)), and handles all display. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.