Skip to content

Module 4 Assignment 2.3 Answer

2.3 Compute Gross Pay

Question

Write a Python program that:

  • Prompts the user for hours worked and hourly rate.
  • Computes the gross pay by multiplying hours and rate.
  • Uses 35 hours and a rate of 2.75 per hour for testing (Expected Output: 96.25).

Correct Python Code

# Prompt user for input
hrs = input("Enter Hours: ")
rate = input("Enter Rate per Hour: ")

# Convert input to float
h = float(hrs)
r = float(rate)

# Compute gross pay
pay = h * r

# Display output
print("Pay:", pay)

Expected Output

Enter Hours: 35
Enter Rate per Hour: 2.75
Pay: 96.25

Explanation

  1. Prompt the user for hours worked (hrs) and hourly rate (rate).
  2. Convert input to float to ensure accurate calculations.
  3. Multiply hours and rate to compute gross pay.
  4. Print the final pay amount in the correct format.

Why This Code is Correct

✅ Uses float() conversion for proper calculations.
✅ Produces expected output (96.25) when tested with 35 hours and 2.75 rate.
✅ Simple and exam-ready solution!