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 including conditional statements and functions, but
not anything beyond that eg not loops
Use the following two step approach. Consider two possible tile orientations relative to the tray's orientation,
ie allowing rotation by degrees:
determine the maximum number of tiles of one orientation that can be placed within the tray, packed
sidebyside and endtoend;
if there is leftover area in the tray, then place as many degree rotated tiles as possible in this leftover
area.
For example, suppose the tray is and the tiles are units unspecified On the left below we can
fit in two tiles two for step and none for step whereas on the right we can fit in three tiles two for step
and one for step 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 numtiles 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?
What is the height of the tray?
What is the width of each tile?
What is the height of each tile?
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 and height and area
The tiles have width and height and area
The maximum number of tiles in the tray is
The total area of the tiles is and the unoccupied area in the tray is
Note that the maximum number of tiles should be the same if the inputted tray andor tiles were rotated
by 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.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
