Advertisement
minusX

Homework 31

May 1st, 2014
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 31. Write a Python program to compute the cost of carpeting three rooms. Carpet cost is $8.95 per square yard. Use four separate functions to collect the dimensions of a room in feet, convert feet into yards, compute the area, and compute the cost per room. The main function should use a loop to process each of the three rooms, then add the three costs, and write out the total cost. (Hints: The function to convert feet into yards must be used twice for each room, with two different arguments. Hence, it does not make sense to try to give the parameter the same name as the argument. See Exercise 11 on how to format output to two decimal places, as is usually done with monetary values.)
  2.  
  3. room = 0
  4. while (room<3):
  5.     length = float(input("Enter the length of the first room in feet: "))
  6.     width = float(input("Enter the width of the first room in feet: "))
  7.     length_yard = float(length/3)
  8.     width_yard = float(width/3)
  9.     room_area = float(length_yard*width_yard)
  10.     room=room+1
  11. print ("The area of the first room is %s square yards." % (room1_area))
  12. print ("The cost of carpeting the first room is $%5.2f." % (room1_area*8.95))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement