Question: Your Task The Problem Exit Fullscreen Congratulations! You have landed a job working for a company that builds robots that do automated packaging. One common

Your Task The Problem
Exit Fullscreen
Congratulations! You have landed a job working for a company that builds robots that do automated
packaging. One common task for these robots is to fill trays with tiles. The trays and tiles are all rectangular,
and the tiles that are chosen to be put on a particular tray are all the same size. The goal is to fit as many
of these tiles onto the given tray. The robot is given the size of the tray and the sizes of the tiles. Your job
is to figure out the maximum number of tiles. Don't worry about how the robot will mechanically place the
tiles on the tray - that's someone else's job!
In this assignment you'll solve a version of this computational problem. You will write a Python program
that does the following: given the size of a tray namely a width and height and given the size of the tiles
(again a width and height) to be put on the tray, determine the maximum number of tiles that can fit on
the tray.
There are several approaches one could take to solve such a problem. However, you are limited to the parts
of the Python language that we covered up to lecture 5 including conditional statements and functions, but
not anything beyond that (e.g. not loops).
Use the following two step approach. Consider two possible tile orientations relative to the tray's orientation,
i.e. allowing rotation by 90 degrees:
determine the maximum number of tiles of one orientation that can be placed within the tray, packed
side-by-side and end-to-end;
if there is leftover area in the tray, then place as many 90 degree rotated tiles as possible in this leftover
area.
For example, suppose the tray is 45 and the tiles are 32(units unspecified). On the left below we can
fit in two tiles (two for step 1 and none for step 2) whereas on the right we can fit in three tiles (two for step
1 and one for step 2). So the maximum number of tiles we can fit using the above approach is three (the
second case).
Your task is specifically to write a function num_tiles that takes no arguments and asks the user for the
width and height of a tray and the width and height of each tile. These inputs entered by the user may be
either integers or floats. Note that the input function treats whatever you type as a string and so you'll need
to cast the value.
Here is an example that corresponds to the figure above:
What is the width of the tray? 4
What is the height of the tray? 5
What is the width of each tile? 2
What is the height of each tile? 3
You may assume that the type of the inputs provided to the program by the user will always be correct. In
particular, you do not need to be concerned that one of the width or height values is negative, or that the
user enters something that is not a number. It could happen, however, that the tile is bigger than the tray
in which case zero tiles can fit on the tray.
The function should not return anything (void). Instead it should print out specific details about the solution
using the following format. Again, the values correspond to the above example.
The tray has width 4.0 and height 5.0 and area 20.0
The tiles have width 2.0 and height 3.0 and area 6.0
The maximum number of tiles in the tray is 3
The total area of the tiles is 18.0 and the unoccupied area in the tray is 2.0
Note that the maximum number of tiles should be the same if the inputted tray and/or tiles were rotated
by 90 degrees (swapping the width or height).
For consistency and ease of grading, we require that the widths and heights and area values are printed out
as float, and we also require that they be rounded to one decimal point. (Use the builtin round function.)
We require that the maximum number of tiles is of type int.
Whenever you write a program to solve a problem, try to break the problem up into subproblems and solve
them separately. Use helper functions to "encapsulate" parts of the problem. For example, in this problem
the steps of reading the input from the user, computing the maximum number of tiles, and printing out the
result are separate parts of the problem and so you might want to have helper functions for some of these
parts. Computing the maximum number of tiles has two steps, so you may ask yourself if a helper function is
appropriate there. There is often no single right way to break down the problem and sometimes you may not
need to write helper functions at all. But if you find yourself writing the same instructions more than once,
or having to scroll up and down too much, then this is a sign you could benefit from helper functions.
Your Task The Problem Exit Fullscreen

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!