.py
files containing your work. (If you upload a screenshot or other file format, you won't get credit.)This homework assignment must be submitted in Gradescope by Noon central time on Wednesday 18 January 2023.
(Note:That's a deviation from the usual schedule where homework is due on Tuesdays.)
Collaboration is prohibited, and you may only access resources (books, online, etc.) listed below.
This assignment is based on the first week of lecture, so it's basically some MCS 260-level coding exercises. Homework 2 will be similar, but more challenging. Homework 3 will be about new material.
The course materials you may refer to for this homework are:
This homework assignment has 2 problems, numbered 2 and 3. The grading breakdown is:
Points | Item |
---|---|
3 | Autograder |
6 | Problem 2 |
6 | Problem 3 |
15 | Total |
The part marked "autograder" reflects points assigned to your submission based on some simple automated checks for Python syntax, etc. The result of these checks is shown immediately after you submit.
Ask your instructor or TA a question by email, in office hours, or on discord.
In Gradescope, the score assigned to your homework submission by the autograder (checking for syntax and docstrings) will be recorded as "Problem 1". Therefore, the numbering of the actual problems begins with 2.
This will happen on every assignment this semester.
One of the exercises on worksheet 1 asked you to make a program to draw a box using unicode box-drawing characters. A 10x5 box (width x height) of that type looks like this:
╔════════╗
║ ║
║ ║
║ ║
╚════════╝
In this problem you'll modify this program in a few ways. First, we'll deal with a simpler version of box-drawing that doesn't involve so many unusual characters. Instead, +
will be used for corners and -
or |
will be used for edges. The box above would be rendered this way as follows:
+--------+
| |
| |
| |
+--------+
In addition to changing the box-drawing symbols, for this problem you will want to think of the box drawn by the other program as a window (as you might have on the wall to look outside), to which we'll be adding a grid that subdivides that window into smaller panes. For example, if the box above were subdivided into a 3x2 grid (horizontal count x vertical count), we'd get this:
+--+--+--+
| | | |
+--+--+--+
| | | |
+--+--+--+
Notice that +
is used for corners and for all 3- and 4-way junctions.
Now, critically, we fix terminology to describe this situation. The grid window shown above would be called a 3x2 grid of 4x3 panes because:
+--+ 4 characters wide
| | 3 lines tall
+--+
Write a program called hwk1prob2.py
that contains the following:
gridwindow
that accepts four integer arguments nx
,ny
, xsize
, ysize
and returns a string. If printed to the screen, that string should look like a nx
x ny
grid of xsize
x ysize
panes.gridwindow
, using the first four command line arguments to get the function arguments (which need conversion to integers), and which prints the return value to the terminal.So for example
python3 hwk1prob2.py 2 5 4 3
means "2x5 grid of 4x3 panes" and should print the following to the terminal and exit:
+--+--+
| | |
+--+--+
| | |
+--+--+
| | |
+--+--+
| | |
+--+--+
| | |
+--+--+
Notes and tricky spots
xsize
and ysize
are the sizes of the smallest rectangles you see, not the overall window.+--++--++--+
| || || |
+--++--++--+ INCORRECT!
+--++--++--+
| || || |
+--++--++--+
nx
and ny
are at least 1, and that xsize
and ysize
are at least 2.Write a program that will find and print the smallest integer perfect square (a number of the form a**2
, with a
an integer) whose expression in base 10 (decimal) contains every one of the digits 0
, 1
, 2
, ..., 9
.
Note you're printing a**2
(the square), not the number a
whose square has this property.
Submit this program as hwk1prob3.py
.