Lab - 5
Lab - 5
Lab Requirements
• PyCharm (IDE).
Version 1.1
09/10/2019
Practice Activities with Lab Instructor (20 minutes)
Write a program that prompts the user to enter the length from the center of a pentagon
to a vertex and computes the area of the pentagon, as shown in the following figure.
3√3 2
The formula for computing the area of a pentagon is 𝐴𝑟𝑒𝑎 = 𝑠 , where s is the length
2
𝜋
of a side. The side can be computed using the formula 𝑠 = 2𝑟 sin , where r is the length
5
from the center of a pentagon to a vertex.
Solution
Write a program that reads the following information and prints a payroll statement:
Employee’s name (e.g., Smith)
Number of hours worked in a week (e.g., 10)
Hourly pay rate (e.g., 9.75)
Federal tax withholding rate (e.g., 20%)
State tax withholding rate (e.g., 9%)
A sample run is shown below:
3
Solution
4
activity_2.py
1 # Get the employee's name
2 name = input("Enter employee's name: ")
3
4 # Get the number of hours worked in a week
5 hours = eval(input("Enter number of hours worked in a week: "))
6 # Get the hourly pay rate
7 payRate = eval(input("Enter hourly pay rate: "))
8 # Get the federal tax withholding rate
9 fedTaxWithholdingRate = eval(input("Enter federal tax withholding rate: "))
10 # Get the state tax withholding rate
11 stateTaxWithholdingRate = eval(input("Enter state tax withholding rate: "))
12
13 # Calculate the gross Pay
14 grossPay = hours * payRate
15 # Calculate the federal Withholding
16 fedTaxWithholding = grossPay * fedTaxWithholdingRate
17 # Calculate the state Withholding
18 stateTaxWithholding = grossPay * stateTaxWithholdingRate
19 # Calculate the total deduction
20 totalDeduction = fedTaxWithholding + stateTaxWithholding
21 # Calculate the net pay
22 netPay = grossPay - totalDeduction
23
24 # Store, prepare and format the output into a string
25 out = "Employee Name: " + name + "\n\n"
26 out += "Hours Worked: " + str(hours) + '\n'
27 out += "Pay Rate: $" + str(payRate) + '\n'
28 out += "Gross Pay: $" + str(grossPay) + '\n'
29 out += "Deductions:\n"
30 out += " Federal Withholding (" + str(fedTaxWithholdingRate * 100) + \
31 "%): $" + str(int(fedTaxWithholding * 100) / 100.0) + '\n'
32 out += " State Withholding (" + str(stateTaxWithholdingRate * 100) + "%):" + \
33 " $" + str(int(stateTaxWithholding * 100) / 100.0) + '\n'
34 out += " Total Deduction:" + " $" + \
35 str(int(totalDeduction * 100) / 100.0) + '\n'
36 out += "Net Pay:" + " $" + str(int(netPay * 100) / 100.0)
37
38 # Display the result
39 print(out)
5
Individual Activities (60 minutes)
The area of a pentagon can be computed using the following formula (s is the length of a
side):
5 × 𝑠2
𝐴𝑟𝑒𝑎 = 𝜋
4 × tan ( )
5
Write a program that prompts the user to enter the side of a pentagon and displays the
area. Here is a sample run:
Write a program that prompts the user to enter a four-digit integer and displays the
number in reverse order. Here is a sample run:
6
Extra Exercises (Homework)