Task 1: Multiplication
Objective: Display the result of multiplying two numbers.
Code Solution:
Explanation: This code multiplies a and b, then prints the result.
Task 2: Half of the Sum
Objective: Display half of the sum of two numbers.
Code Solution:
Explanation: The code adds a and b, divides the sum by 2, and displays the result.
Task 3: Perimeter and Area of a Rectangle
Objective: Calculate the perimeter and area of a rectangle.
Code Solution:
Explanation: This code calculates both perimeter and area for a rectangle with given sides.
Task 4: Calculate Body Mass Index (BMI)
Objective: Calculate BMI using the formula: BMI = weight (kg) / height (m)².
Code Solution:
Explanation: The function calculates BMI using weight and height and displays the result.
Task 5: Buy Ticket for Adult Movie Session
Objective: Allow buying a ticket only if the person is older than 16 years.
Code Solution:
Explanation: This function checks the age and determines if the person can buy a ticket.
Comparison Table
| Task | Code Example Summary | Expected Output |
|---|---|---|
| Multiplication | Multiplies two numbers a and b. | 18 |
| Half of the Sum | Calculates half of (a + b). | 4.5 |
| Perimeter and Area | Calculates perimeter and area of a rectangle. | Perimeter: 18, Area: 18 |
| Calculate BMI | Computes BMI based on weight and height. | 22.86 |
| Buy Ticket for Adult Session | Checks if age is greater than 16 for ticket sale. | "You can buy a ticket for the adult session." |