This assignment is primarily python. You should only use python features that we have discussed up to this point. If you have questions about whether or not a particular feature can/should be used, ask the instructors!
When grading your assignments, each problem will be thoroughly tested with many types of input, so make sure you test your scripts/functions well!
The python in this assignment will be graded using python 3.6. Any python version 3.4 or newer should suffice though.
All of your scripts should be well-formatted and easy for the graders to read. Each script should have a header comment at the top that has the following format:
#
# Author: Student Name
# Description:
# A short description of what this program / script / set of functions does!
#
If any part of your scripts are particularly complex, you should put documentation comments above those lines of code.
You should test each function that you write thoroughly, with many different values for the argument(s). However, make sure that when you submit your script files there are no calls to the functions, only the function(s) by themselves.
You are encouraged to use the techniques described in lab 4 to run and test the functions you need to write for this assignment.
In this problem, you will write a python file called functions.py
.
In this file, you will write several functions that compute various values / strings.
All of the functions described below should be placed in this file.
Write a function named fahr_to_cel
.
This function will take a single numeric argument named temperature
.
It will treat the input value as a temperature in Fahrenheit, and return the equivalent Celsius value.
This function should round down to the nearest full degree.
Write a function named cel_to_fahr
.
This function will do the opposite of the previous one.
It will take a single numeric argument named temperature
, which it will treat as a temperature in Celsius.
It will return the equivalent temperature in Fahrenheit.
This function should round down to the nearest full degree.
Write a function named box_size
.
This function will compute the volume of a box with the provided dimensions.
The function will take three arguments.
The first is the width, the second is the length, and the third is the height.
The function will return a numeric value representing the volume of the box.
Write a function named cube_size
.
This function will compute the volume of a cube.
The length of the sides will be passed as the first and only argument.
You are not allowed to use any mathematical operators to implement this function.
Instead, use the return value of one of the above functions you already implemented (volume).
Below is a sample python sessions that imports the functions
module, and makes a few calls to these functions.
You should get the same results as these when running your functions:
$ python3.6
Python 3.6.0 (default, Dec 24 2016, 08:01:42)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> import functions
>>>
>>> functions.fahr_to_cel(123)
50
>>> functions.fahr_to_cel(75)
23
>>> functions.fahr_to_cel(32)
0
>>> functions.fahr_to_cel(-5)
-20
>>> functions.fahr_to_cel(-10)
-23
>>>
>>>
>>> functions.cel_to_fahr(123)
253
>>> functions.cel_to_fahr(75)
167
>>> functions.cel_to_fahr(32)
89
>>> functions.cel_to_fahr(-5)
23
>>> functions.cel_to_fahr(-10)
14
>>>
>>>
>>> functions.box_size(1, 2, 3)
6
>>> functions.box_size(12, 10, 8)
960
>>> functions.box_size(9, 9, 7)
567
>>> functions.box_size(3, 5, 5)
75
>>>
>>> functions.cube_size(3)
27
>>> functions.cube_size(19)
6859
>>> functions.cube_size(10)
1000
>>> functions.cube_size(7)
343
>>>
In this problem, you will write a script named bat.py
.
This function will contain one function named print_bat
.
This function’s responsibility is to print ascii art of a bat to stdout.
This function will take one argument named wing_length
, which will specify the length/size of each wing of the bat.
This value can be any positive integer or 0.
When this function is called with a wing_length
of 0, the following will be printed:
_ ,_, _
/ `-) (-` \
/.-.-\ /-.-.\
"
Since this is what the bat looks like with a wing_length
of zero, this is the smallest bat the function will print.
When passed a wing_length
value of 1, the bat will print like:
_ ,_, _
/ `--) (--` \
/.-.-,\ /,-.-.\
"
Notice that the wing length on each side has been widened by 1 character.
There is an extra dash (-
) character on the top of the wing, and an extra comma (,
) at the bottom.
When wing_length
is 5, the wings will have 5 extra commas/dashes:
_ ,_, _
/ `------) (------` \
/.-.-,,,,,\ /,,,,,-.-.\
"
There are now 5 extra dash (-
) characters on the top of the wing, and 5 extra commas (,
) at the bottom.
And when wing_length
is 23, each wing will have 23 dashes/commas:
_ ,_, _
/ `------------------------) (------------------------` \
/.-.-,,,,,,,,,,,,,,,,,,,,,,,\ /,,,,,,,,,,,,,,,,,,,,,,,-.-.\
"
The ascii art should print exactly as is show in these examples, so type carefully! You should test this function thoroughly, with many different values for the argument(s). However, make sure that when you submit the script file there are no call to the function, only the function itself.
In this problem, you will write a script named needle.py
.
This function will contain one function named print_space_needle
.
This function’s responsibility is to print ascii art of the Seattle space needle to standard output.
This function will take three command line arguments.
The first will be a numeric value named tower_height
, which specifies the height of the main tower.
The second will be a numeric value named lookout_height
, which specifies the height of the viewing deck.
The third will be a numeric value named antenna_height
, which specifies the height of the tower’s antenna.
All of these values may be any positive integer, or 0.
When the arguments are 0, 0, 0 (respectively), the following will be printed:
*
|
_____|||_____
/=============\
\-------------/
\___________/
/||:::||\
/ ||:::|| \
___/__||:::||__\___
/~~~~~~~~~~~~~~~~~~~\
|_____________________|
When the argument are 7, 0, 0 (respectively), the following will be printed:
*
|
_____|||_____
/=============\
\-------------/
\___________/
||:::||
||:::||
||:::||
||:::||
||:::||
||:::||
||:::||
/||:::||\
/ ||:::|| \
___/__||:::||__\___
/~~~~~~~~~~~~~~~~~~~\
|_____________________|
When the argument are 0, 7, 0 (respectively), the following will be printed:
*
|
_____|||_____
/=============\
|~~~~~~~~~~~~~~~|
|~~~~~~~~~~~~~~~|
|~~~~~~~~~~~~~~~|
|~~~~~~~~~~~~~~~|
|~~~~~~~~~~~~~~~|
|~~~~~~~~~~~~~~~|
|~~~~~~~~~~~~~~~|
\-------------/
\___________/
/||:::||\
/ ||:::|| \
___/__||:::||__\___
/~~~~~~~~~~~~~~~~~~~\
|_____________________|
When the argument are 0, 0, 7 (respectively), the following will be printed:
*
|
|||
|||
|||
|||
|||
|||
|||
_____|||_____
/=============\
\-------------/
\___________/
/||:::||\
/ ||:::|| \
___/__||:::||__\___
/~~~~~~~~~~~~~~~~~~~\
|_____________________|
Finally, here is one last example, where the arguments are 20, 5, and 3 respectively:
*
|
|||
|||
|||
_____|||_____
/=============\
|~~~~~~~~~~~~~~~|
|~~~~~~~~~~~~~~~|
|~~~~~~~~~~~~~~~|
|~~~~~~~~~~~~~~~|
|~~~~~~~~~~~~~~~|
\-------------/
\___________/
||:::||
||:::||
||:::||
||:::||
||:::||
||:::||
||:::||
||:::||
||:::||
||:::||
||:::||
||:::||
||:::||
||:::||
||:::||
||:::||
||:::||
||:::||
||:::||
||:::||
/||:::||\
/ ||:::|| \
___/__||:::||__\___
/~~~~~~~~~~~~~~~~~~~\
|_____________________|
Again, the ascii art should print exactly as is show in these examples, so type carefully!
The last two problems in this assignment require printing out intricate text designs. As already mentioned, it is important to be precise when doing these printouts.
We will try not to take points off for very minor differences (for example, minor character spacing issues). However, we will take points off for any non-trivial differences, so try to be as precise as you can!
This problem will be graded out of 100 points.
This was assigned on Thursday, February 12, 2017. It is due Friday, February 17, 2017, at 6:00pm.
Turn-in instructions:
.py
file in a directory named netid-assignment-4
where netid
is your netid. Make sure only the .py
files exist in this directory, no others.netid-assignment-4
directory. The result should be named netid-assignment-4.zip
. There are instructions online for how to do this with a Mac and how to do this with a PC. Make sure to zip the directory, not the files individually!netid-assignment-4.zip
to the assignment-4 D2L dropbox.Following these turn-in instructions closely is very important, because our grading scripts will depend on some of the details. You may lose points if these instructions are not followed precisely!