The due date for this homework is Friday, February 9th, 11pm EDT
This assignment is designed to give you practice with the following new topics:
Your task is to complete following steps:
Download the hw2.zip
file from the course website and open it. You will see three python
files, hw2_garden.py
, hw2_owls.py
and
hw2_tower.py
in the unzipped folder. You are expected to
write your programs in these files.
Complete hw2_tower.py
. This file is used in Part 1.
Complete hw2_garden.py
. This file is used in Part 2.
Complete hw2_owls.py
. This file is used in Part 3.
Review the grading criteria at the end of this assignment.
Submit your completed programs.
Notice that each starter .py
file has a header with some
information for you to fill in. Please do so. Your feedback helps the
instructors better understand your experiences doing the homeworks and
where we can provide better assistance.
Tower
Your task is to design and implement a program that draws a particular text-art pattern (a tower), much like you did in lab 2:
||
||
__{{}}__
__{::::::::}__
||||||||||||||
(_)()()()()(_)
(_)()()(_)
____][____
___][___
||
||
|%%%%%%|
|%%%%%%|
|%%%%%%|
|%%%%%%|
__{{}}__
__{::::::::}__
||||||||||||||
You must use separate functions for distinct features and to increase reusability while reducing repetition in your code. Note that there are distinct segments to the figure as well as repeated elements which lend themselves naturally to implementing as separate functions.
For this problem, we are providing you with the code statements to calculate the materials needed for an ornamental garden according to the design below. In this garden design, the blue areas represent flowerbeds and the yellow areas are filled with stone, mulch, or other fill material. The garden is a perfect square. The four outer flowerbeds are congruent semicircles and the central flowerbed is a perfect circle.
The program prompts the user for the following information:
The side length (in feet) of the finished garden.
The recommended spacing (in feet) between plants.
The depth (in feet) of the flowerbeds.
The depth (in feet) of the filled areas.
Next it calculates and prints the following quantaties needed for the garden:
Number of plants for each type of flowerbed (semicircle and circle) and total number of plants for the garden.
Cubic yards of soil for each type of flowerbed (semicircle and circle) and total cubic yards of soil for the garden, rounded to one decimal place. Note that there are 3 (linear) feet in 1 (linear) yard.
Total cubic yards of fill material for the garden, rounded to one decimal place. Again, note that there are 3 feet in 1 yard.
Example output 1
Enter length of side of garden (feet): 10
Enter spacing between plants (feet): 0.5
Enter depth of garden soil (feet): 0.8333
Enter depth of fill (feet): 0.8333
Plants for each semicircle garden: 39
Plants for the circle garden: 78
Total plants for garden: 234
Soil for each semicircle garden: 0.3 cubic yards
Soil for the circle garden: 0.6 cubic yards
Total soil for the garden: 1.8 cubic yards
Total fill for the garden: 1.3 cubic yards
Example output 2:
Enter length of side of garden (feet): 13
Enter spacing between plants (feet): 0.25
Enter depth of garden soil (feet): 0.5
Enter depth of fill (feet): 0.25
Plants for each semicircle garden: 265
Plants for the circle garden: 530
Total plants for garden: 1590
Soil for each semicircle garden: 0.3 cubic yards
Soil for the circle garden: 0.6 cubic yards
Total soil for the garden: 1.8 cubic yards
Total fill for the garden: 0.6 cubic yards
The provided program is correct, you must test it with the provided examples to understand its behavior. Your task is to come up with an optimal design for this program that splits the provided code statements across different functions based on distinct features to increase reusability (and reduce repetition). Here are the rules that your optimal-design program must follow:
The behavior, functionality and output must be the same as the provided program (you shouldn’t need to modify the provided code statements, check with your instructor before you change code statements).
Your code must also define a main
function that
represents the entry point into your program (that is, the first thing
that gets executed) and calls the other functions. Therefore, you are
allowed to put the user input statements inside main
(you
are not required, but you may).
The program must prompt the user 4 times and **only* 4 times for the respective information needed by the program. Your program must optimally transfer information between functions using the function mechanisms of parameter passing and return we learned in class.
All the provided code statements must be inside a function, the
only code statements that should be outside (in the global scope of the
program) is the function call to main()
.
Sitting Owls
For this problem, you need to write a program that draws two owls sitting on a branch at a distance that is randomly picked between 5 and 20 (inclusive) spaces. One possible output could be:
.-"-. .-"-.
/ 4 4 \ / 4 4 \
\_ v _/ \_ v _/
// \\ // \\
(( )) (( ))
=""===""=======""===""=
||| |||
To get you started, we have already provided you with a design for
the program in hw2_owls.py
. Fill in the provided functions
(note that when you are done implementing a function, you must remove
pass
) and call them respectively to accomplish this
task.
Printing the backslash character \
is tricky because
python uses the backslash to produce special characters. For example,
the string "\t"
is a tab and "\n"
is a
newline. A single backslash character is represented by a string of two
backslash characters ("\\"
). For example:
print("/\\/\\")
will print: /\/\
Your assignment will be graded on two criteria:
Correctness and Design [90%], broken down as follows:
Category | Portion of grade |
---|---|
Part 1 | 30% |
Part 2 | 30% |
Part 3 | 30% |
Program formatting and style [10%]: style and formatting become increasingly important the more complex your program becomes. For these first programs, adhere to the following guidelines:
You may extend Part 3 to print multiple (3+) different looking owls together on a branch. Some examples of different looking owls are:
.---.
/ _ _ \
\_ v _/
// \\
(( ))
=========
|||
.-"-.
/ 6_6
\_ (__\
// \\
(( ))
=""===""=
|||