π Day 20/150 – Area of a Triangle in Python
Calculating the area of a triangle is a classic beginner-friendly problem that helps you understand formulas, user input, and different coding styles in Python.
The most common formula is:
Let’s explore multiple ways to implement this π
πΉ Method 1 – Basic Method (Direct Calculation)
π§ Explanation:
- We directly assign values to base and height.
- 0.5 * base * height calculates the area.
- Simple and easy to understand.
π Best for: Quick calculations and beginners.
πΉ Method 2 – Taking User Input
π§ Explanation:
- input() allows user interaction.
- float() converts input into numbers.
- Same formula is applied afterward.
π Best for: Dynamic, real-world scenarios.
πΉ Method 3 – Using a Function
π§ Explanation:
- Function triangle_area() takes b and h as parameters.
- return gives back the computed value.
- Makes code reusable and clean.
π Best for: Structured and reusable programs.
πΉ Method 4 – Using Lambda Function
π§ Explanation:
- lambda is a short, one-line function.
- Useful for simple operations without defining a full function.
π Best for: Short and quick logic.
.png)
.png)

