COSC 101 Homework 2: Spring 2024

The due date for this homework is Friday, February 9th, 11pm EDT

Introduction

This assignment is designed to give you practice with the following new topics:

Your assignment

Your task is to complete following steps:

  1. 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.

  2. Complete hw2_tower.py. This file is used in Part 1.

  3. Complete hw2_garden.py. This file is used in Part 2.

  4. Complete hw2_owls.py. This file is used in Part 3.

  5. Review the grading criteria at the end of this assignment.

  6. 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.

Part 1

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.

Part 2

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:

  1. The side length (in feet) of the finished garden.

  2. The recommended spacing (in feet) between plants.

  3. The depth (in feet) of the flowerbeds.

  4. The depth (in feet) of the filled areas.

Next it calculates and prints the following quantaties needed for the garden:

  1. Number of plants for each type of flowerbed (semicircle and circle) and total number of plants for the garden.

  2. 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.

  3. 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:

Part 3

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.

Important Note

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: /\/\

Grading

Your assignment will be graded on two criteria:

  1. Correctness and Design [90%], broken down as follows:

    Category Portion of grade
    Part 1 30%
    Part 2 30%
    Part 3 30%
  2. 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:

Challenge

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 
 \_  (__\
 //   \\ 
((     ))
=""===""=
   |||