🐍 In Python, calculate the total cost of tile it would take to cover a floor plan of width and height, using a cost entered by the user.
if roomlen!=0 and roomwid!=0 and tilelen!=0 and tilewid!=0:
if roomlen%tilelen==0:
notileslen = int(roomlen//tilelen)
if roomwid%tilewid==0:
notileswid = int(roomwid//tilewid)
else:
notileswid = int((roomwid//tilewid)+1)
elif roomlen%tilewid==0:
notileslen = int(roomlen//tilewid)
if roomwid%tilelen==0:
notileswid = int(roomwid//tilelen)
else:
notileswid = int((roomwid//tilelen)+1)
else:
notileslen = int((roomlen//tilelen)+1)
if roomwid%tilewid==0:
notileswid = int(roomwid//tilewid)
else:
notileswid = int((roomwid//tilewid)+1)
print(f'No. of tiles on longside: {notileslen}')
print(f'No. of tiles on wideside: {notileswid}')
print(f'Total no. of tiles required: {notileslen*notileswid}')
return tileprice*(notileslen*notileswid)
else:
print("Measurement cannot be zero.")
if __name__=='__main__':
roomlen = float(input("Enter the length of the room in feet: "))
roomwid = float(input("Enter the width of the room in feet: "))
tilelen = float(input("Enter the length of the tile in feet: "))
tilewid = float(input("Enter the width of the tile in feet: "))
tileprice = float(input('Enter price of each tile: '))
print(f'Cost of all the tiles combined: {tile_calculator(roomlen, roomwid, tilelen, tilewid, tileprice)}')
Solution
def tile_calculator(roomlen, roomwid, tilelen, tilewid, tileprice):if roomlen!=0 and roomwid!=0 and tilelen!=0 and tilewid!=0:
if roomlen%tilelen==0:
notileslen = int(roomlen//tilelen)
if roomwid%tilewid==0:
notileswid = int(roomwid//tilewid)
else:
notileswid = int((roomwid//tilewid)+1)
elif roomlen%tilewid==0:
notileslen = int(roomlen//tilewid)
if roomwid%tilelen==0:
notileswid = int(roomwid//tilelen)
else:
notileswid = int((roomwid//tilelen)+1)
else:
notileslen = int((roomlen//tilelen)+1)
if roomwid%tilewid==0:
notileswid = int(roomwid//tilewid)
else:
notileswid = int((roomwid//tilewid)+1)
print(f'No. of tiles on longside: {notileslen}')
print(f'No. of tiles on wideside: {notileswid}')
print(f'Total no. of tiles required: {notileslen*notileswid}')
return tileprice*(notileslen*notileswid)
else:
print("Measurement cannot be zero.")
if __name__=='__main__':
roomlen = float(input("Enter the length of the room in feet: "))
roomwid = float(input("Enter the width of the room in feet: "))
tilelen = float(input("Enter the length of the tile in feet: "))
tilewid = float(input("Enter the width of the tile in feet: "))
tileprice = float(input('Enter price of each tile: '))
print(f'Cost of all the tiles combined: {tile_calculator(roomlen, roomwid, tilelen, tilewid, tileprice)}')
Comments
Post a Comment