Difference between revisions of "Area Calculation"
m |
|||
Line 5: | Line 5: | ||
|Body= | |Body= | ||
− | === | + | ===Step 1: Get inputs/outputs needed to solve the problem=== |
You will need the following in order to solve this problem. | You will need the following in order to solve this problem. | ||
<li>costPSF - The cost of materials per square foot. | <li>costPSF - The cost of materials per square foot. | ||
Line 16: | Line 16: | ||
<li>input - Python keyword used to get input from the user | <li>input - Python keyword used to get input from the user | ||
− | === | + | ===Step 2: Write the program=== |
Line 40: | Line 40: | ||
}} | }} | ||
− | === | + | ===Step 3: Display the output of the program=== |
Sample output with length = 20 and width = 30 | Sample output with length = 20 and width = 30 | ||
Line 51: | Line 51: | ||
}} | }} | ||
− | === | + | ===Step 4: Contrast with Calculating Area in program a day example=== |
This Python program performs exactly the same function as the Java Calculate area program in Program a Day. | This Python program performs exactly the same function as the Java Calculate area program in Program a Day. |
Revision as of 06:49, 4 April 2012
COMP 1010 Home > Back to Extra Labs
IntroductionIt's time to replace the ceiling in your living room, but you are not sure how much it will cost? The required materials cost $8 per square foot plus an installation fee of $500. Your roommate has agreed to pay half, and you have a coupon for $50 off the total cost. Write a program that accepts the length and width (as integers) of a room. Calculate the total cost (as a double) of ceiling by multiplying the square footage by the price per square foot, plus installation. Your program will print total square footage, total cost, and your cost (half the total cost less the coupon) |
---|
Step 1: Get inputs/outputs needed to solve the problem
You will need the following in order to solve this problem.
Step 2: Write the program
# This program is used to calculate the area # and cost of replacing the ceiling in your # living room costPSF = 8 coupon = 50 installFee = 500 length = input("Input length:") width = input("Input width:") area = length * width totalCost = (area * costPSF) + installFee print "Total area: %f " % area + "square feet" print "Total cost: $%f" % totalCost print "Your cost: $%f" % ((totalCost / 2) - coupon)
Step 3: Display the output of the program
Sample output with length = 20 and width = 30
Total area: 600 square feet Total cost: $5300.0 Your cost: $2600.0
Step 4: Contrast with Calculating Area in program a day example
This Python program performs exactly the same function as the Java Calculate area program in Program a Day. But, there only some slight differences as shown below.