There are two problems in this week’s problem set, one requires us to calculate the radiation exposure, another one requires us to program a hangman game.

**Radiation exposure**

Radioactive substance will undergo radioactive decay and emit radiation, over time, the amount of radioactive substance will reduce. The time required for a radioactive substance to reduce half of its amount is called half-life. Different radioactive substance has different half-life. For example, the half-life of Copernicium-285, Cn-285 is 29 seconds, this means if we start off with 4 grams of Cn-285, it will reduce to 2 grams after 29 seconds, and it will reduce to 1 gram in another 29 seconds. Other radioactive substance has long half-life, for example, Uranium-238, U-238 has a half-life of 4.47 billion years, its long half-life makes it useful for radiometric dating.

The amount of radioactive substance at any given time can be plotted as a graph. From the graph below, we can see the amount of radioactive substance/ radioactivity decreases by time.

The problem of this week is, calculate the amount of radioactive exposure for a given time period. If a human were exposed to radioactive substance at time 5 to time 25, how do we know how much radioactivity has accumulated over that time period? The answer is , which is the area under the graph.

Then the question is how do we calculate the area under the graph? We can do this by drawing rectangle of height f(x) at given x, and width of a fixed size. From time 5 to time 25, it can be divided into 5 rectangles of width 5, the height will be the f(x) value. This method can only give an approximation of area under the graph, as for each rectangle, there is part of the rectangle that is not in the area under the graph, specifically, the top right corner of rectangle. However, we can improve this approximation by using rectangles of smaller width, say separate the rectangle from time 5 to time 25 into 20 rectangles, with 1 width each, this will reduce the amount of extra part of rectangles that is not in area under the graph.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
def f(x): import math return 10*math.e**(math.log(0.5)/5.27 * x) def radiationExposure(start, stop, step): ''' Computes and returns the amount of radiation exposed to between the start and stop times. Calls the function f (defined for you in the grading script) to obtain the value of the function at any point. start: integer, the time at which exposure begins stop: integer, the time at which exposure ends step: float, the width of each rectangle. You can assume that the step size will always partition the space evenly. returns: float, the amount of radiation exposed to between start and stop times. ''' total = 0 current = start while current < stop: total += f(current) * step current += step return total |

**Hangman**

In this game of Hangman, we are given a words.txt file containing many words, which will be chosen at random for our user to guess. The whole script’s main part is as follows:

1 2 3 |
wordlist = loadWords() secretWord = chooseWord(wordlist).lower() hangman(secretWord) |

This is short, however the functions that work behind the scene is long. First, `chooseWord`

function will choose a word randomly from `wordlist`

, which was loaded previously, then assign the word to variable secretWord. The secretWord is passed to `hangman`

function. In this problem set, we need to code the `hangman`

function. `hangman`

function has 3 other functions that can help it do its work, `isWordGuessed`

, `getGuessedWord`

, and `getAvailableLetters`

. Besides coding the `hangman`

function, we also need to code the three functions `hangman`

will later depend on.

`isWordGuessed`

returns True if all the letters of secretWord are in lettersGuessed (meaning when user finally guessed all the correct letters). `getGuessedWord`

returns string, comprised of letters and underscores that represents what letters in secretWord have been guessed so far ( e.g. _ E _ E P _ O N E). `getAvailableLetters`

returns string, comprised of letters that represents what letters have not yet been guessed.

Then, we code the `hangman`

function. The pseudocode is as follows:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
print("Welcome to the game Hangman!") print("I am thinking of a word that is " + str(len(secretWord)) +" letters long") print("-----------") lettersGuessed = [] guesses = 8 # while all the letters of secretWord are not yet in lettersGuessed and guesses left is more than 0 while not isWordGuessed(secretWord, lettersGuessed) and guesses > 0: # print first line print("You have " + str(guesses) +" guesses left") # print second line print("Available Letters: " + getAvailableLetters(lettersGuessed)) # print third line # if user input a letter that has already been entered, reprompt for letter while True: guessLetter = raw_input("Please guess a letter: ").lower() if guessLetter in lettersGuessed: print("Oops! You've already guessed that letter: " + getGuessedWord(secretWord, lettersGuessed)) print("-----------") print(" You have " + str(guesses) +" guesses left") print("Available Letters: " + getAvailableLetters(lettersGuessed)) else: break lettersGuessed += guessLetter # print last line # if correctly guessed secret word if isWordGuessed(secretWord, lettersGuessed): print("Good guess: " + getGuessedWord(secretWord, lettersGuessed)) print("-----------") print("Congratulations, you won!") break # else if the guess letter is in secret word elif guessLetter in secretWord: print("Good guess: " + getGuessedWord(secretWord, lettersGuessed)) print("-----------") # else the guess letter is not in secret word else: print("Oops! That letter is not in my word: " + getGuessedWord(secretWord, lettersGuessed)) print("-----------") guesses -= 1 # if ran out of guesses if guesses == 0: print("Sorry, you ran out of guesses. The word was " + secretWord + ".") |

your answer for Radiation exposure not satisfy all conditions. pleaz check and review it.