Lab 4
Lab 4
Lab 4
Lab Requirements
PyCharm (IDE).
1
Practice Activities with Lab Instructor (20 minutes)
Body mass index (BMI) is a measure of health based on weight. It can be calculated by
taking your weight in kilograms and dividing it by the square of your height in meters.
Write a program that prompts the user to enter a weight in pounds and height in inches
and displays the BMI.
Note that one pound is 0.45359237 kilograms and one inch is 0.0254 meters.
Here is a sample run:
Solution
3
Problem 2 Programming Exercises (2.19)
Write a program that reads in an investment amount, the annual interest rate, and the
number of years, and displays the future investment value using the following formula:
For example, if you enter the amount 1000, an annual interest rate of 4.25%, and the
number of years as 1, the future investment value is 1043.33. Here is a sample run:
Solution
4
Phase 2: Implementation Phase:
1. Open the project “Lab 4” if it was not opened or create it if it was not existing.
2. Create a new file and name it “activity_2.py”.
3. Write the following code in the file:
activity_2.py
1 # Enter the investment amount
2 investmentAmount = eval(
3 input("Enter the investment amount, for example 120000.95: "))
4 # Enter yearly interest rate
5 annualInterestRate = eval(
6 input("Enter annual interest rate, for example 8.25: "))
7 # Enter number of years
8 numberOfYears = eval(
9 input("Enter number of years as an integer, for example 5: "))
10
11 # Calculate monthly interest rate
12 monthlyInterestRate = (annualInterestRate / 100) / 12
13 # Calculate the number of months
14 numberOfMonths = numberOfYears * 12
15 # Calculate the future investment value
16 futureValue = investmentAmount * \
17 ((1 + monthlyInterestRate) ** numberOfMonths)
18
19 # Display the result
20 print("Future value is", int(futureValue * 100) / 100.0)
5
Individual Activities (60 minutes)
Write a program that reads the subtotal and the gratuity rate and computes the gratuity
and total. For example, if the user enters 10 for the subtotal and 15% for the gratuity rate,
the program displays 1.5 as the gratuity and 11.5 as the total.
Here is a sample run of the program:
If you know the balance and the annual percentage interest rate, you can compute the
interest on the next monthly payment using the following formula:
Write a program that reads the balance and the annual percentage interest rate and
displays the interest for the next month. Here is a sample run:
Enter balance and interest rate (e.g., 3 for 3%): 1000, 3.5 <enter>
The interest is 2.91667
6
Extra Exercises (Homework)