In: Computer Science
IN PYTHON ( Use Fuctions and or with Loop if comfortable)
Your friends just bought a new five room house and need your help to know how much it will cost to re-do the floors. Write a program that, given the dimensions of each of the five rooms and the desired type of flooring, outputs the cost of each room as well as the total cost. Hardwood costs $1.39/sqft, carpet costs $3.99/sqft, and tile costs $4.99/sqft. Input Validation: Your program must work regardless of the case the floor option is typed in and any blank spaces surrounding it; If an invalid option is given, inform the user it was invalid and that you will be skipping that room (treat the cost as zero). Round: Use the round function to round your output to two decimal places.
code :
output :
raw_code :
cost = 0
#loop for five rooms
for i in range(1,6):
print('Room : ',str(i))
#taking inputs
length = float(input('Length : '))
width = float(input('Width : '))
floor = input('Flooring : ')
#checking invalid condition
if (floor not in ['Hardwood','carpet','tile']):
print('Invalid type')
continue
#calculating cost
else:
if(floor == 'Hardwood'):
cost += length*width*1.39
elif(floor == 'carpet'):
cost += length*width*3.99
else:
cost += length*width*4.99
#displaying cost with two decimals
print('Cost to re-do floors is $',round(cost,2))
***do comment for queries and rate me up***