This assignment will involve writing several Python functions and performing experiments with those functions. You should begin by downloading a copy of hw3.pytxt and renaming it lastnameHW3.py, where lastname is your last name (e.g., reedHW3.py). Your functions should be defined in this file, and should all follow the style of existing functions (e.g., meaningful names, doc strings).
Note: this work must be entirely your own, with no outside assistance other than the instructor.
The first section of hw3.py contains several weather-related functions. You are to build upon these by defining your own functions.
windChill
function calculates the wind chill index (the temperature experienced by an exposed human in winter). You are to define a related function, windChillC, that similarly calculates the wind chill but with input and output temperatures in degrees Celsius. Note: your function should make use of the existing windChill
function by converting the input temperature into degrees Fahrenheit, calling windChill
to calculate the wind chill index, and then converting the it back to degrees Celsius.
dewPoint
function should take two inputs, the temperature (in degrees Fahrenheit) and the relative humidity (a percentage between 0 and 100), and return the dew point (in degrees Fahrenheit) as defined by the following formula:
The dewPointC
function should similarly calculate the dew point, but with the input and output temperatures in degrees Celsius.
Note: as before, it should make use of the existing dewPoint
and temperature conversion functions.
The second section of hw3.py contains several functions for generating random sentences. The article, noun, and verb functions each return a randomly selected word of that type. The sentence function calls each of these other functions to construct a simple sentence consisting of an article, noun, and verb (in that order). For example, "the man kicked." This simple sentence structure can be defined by a grammar rule:
Update your code to generate sentences based on these grammar rules. In
particular, you must define new functions called adjective,
preposition, nounPhrase, verbPhrase, and
prepPhrase that return the appropriate type of word or phrase.
For example, the call sentence() might produce "the big man by a tree
hit a green ball above some woman" or "some nice woman beside the ball liked a big
man by the house". Note: there should be exactly one space between words.
From looking at these grammar rules, what is the fewest number of words possible in
a sentence? Similarly, what is the greatest number of words possible in a
sentence?
Justify your answers.
random
module, which randomly chooses from a list of options, will prove useful here. In particular, whenever
you want an optional part of speech, you can call the random.choice function
with two options to select from: the part of speech and the empty string "". For example, the following call will either return an adjective
or the empty string.
Note: as before, there should be exactly one space between words in the sentence.
The third section of hw3.py contains several functions for drawing shapes in turtle graphics. The O
function displays a capital 'O' as a series of turtle movements, while the o
function displays a lowercase 'o'. In class you will be assigned a letter of the alphabet, and must define similar functions that display that letter (both uppercase and lowercase versions). For example, if you were assigned the letter A, you would need to define drawing functions named A
and a
.
There are very specific conditions that your letter drawing functions must follow.