Question
Fix the functions so that they generate the correct output. Note there is no need to change the def ...(): line or the documentation strings.
Fix the functions so that they generate the correct output. Note there is no need to change the def ...(): line or the documentation strings. Currently, these are only 'stub' implementations which output the right type of answer, but not the right answer.
The function calls at the end are example
1. Translate
2. get_params
3. newton
4. FizzBuzz
5. [optional] Hamming's problem as described by Dijkstra
gencode = { 'ATA':'I', 'ATC':'I', 'ATT':'I', 'ATG':'M', 'ACA':'T', 'ACC':'T', 'ACG':'T', 'ACT':'T', 'AAC':'N', 'AAT':'N', 'AAA':'K', 'AAG':'K', 'AGC':'S', 'AGT':'S', 'AGA':'R', 'AGG':'R', 'CTA':'L', 'CTC':'L', 'CTG':'L', 'CTT':'L', 'CCA':'P', 'CCC':'P', 'CCG':'P', 'CCT':'P', 'CAC':'H', 'CAT':'H', 'CAA':'Q', 'CAG':'Q', 'CGA':'R', 'CGC':'R', 'CGG':'R', 'CGT':'R', 'GTA':'V', 'GTC':'V', 'GTG':'V', 'GTT':'V', 'GCA':'A', 'GCC':'A', 'GCG':'A', 'GCT':'A', 'GAC':'D', 'GAT':'D', 'GAA':'E', 'GAG':'E', 'GGA':'G', 'GGC':'G', 'GGG':'G', 'GGT':'G', 'TCA':'S', 'TCC':'S', 'TCG':'S', 'TCT':'S', 'TTC':'F', 'TTT':'F', 'TTA':'L', 'TTG':'L', 'TAC':'Y', 'TAT':'Y', 'TAA':'_', 'TAG':'_', 'TGC':'C', 'TGT':'C', 'TGA':'_', 'TGG':'W'}
def translate(nuc): """ Translate a nucleotide sequence (containing letters from ATGC) to a protein sequence (containing one-character abbreviations for the 20-common amino acids).
translate('ATG') M translate(' 1 AtG CAT gat') 'MHD' translate(' 1 atggaagaat cacaggcaga actcaatgtg gagccccctc tgagtcag') 'MEESQAELNVEPPLSQ' """ prot = [] for i in range(2): prot += gencode[nuc[i:i+3]] return "".join(prot)
# Given a list of parameter names and a list of numeric values, create # a dictionary mapping names to values. def get_params(sparams): r""" Input: sparams : str Output: params : dict >>> get_params("atoms = 100") {'atoms': 100.0} >>> get_params("dt = 0.001 " \ ... +"temp = 300 ") {'dt': 0.001, 'temp': 300.0} >>> get_params("press = 10 " \ ... +"vol = 220 ") {'press': 10.0, 'vol': 220.0} >>> get_params("dt = 0.002 " \ ... +"N = 3000 " \ ... +"temp = 320 " \ ... +"press = 1 " \ ... +"L = 20 ") {'press': 1.0, 'dt': 0.002, 'L': 20.0, 'temp': 320.0, 'N': 3000.0} """ return {'dt': 0.001, 'N': 400.0}
def newton(x, v, m, k, dt): ''' Carry out one step of Newton's equation, F = m a Using the Euler integration scheme with timestep 'dt'. The force should be computed using Hook's law: F = -k*x >>> newton(1.0, 0.0, 1.0, 0.3, 0.1) (1.0, -0.03) >>> newton(0.2,-0.2, 1.0, 0.4, 0.02) (0.196, -0.2016) >>> newton(0.5, 0.1, 1.0, 0.2, 0.05) (0.505, 0.095) >>> newton(-0.2, -0.1, 1.0, 0.3, 0.01) (-0.201, -0.0994) ''' return (x, v)
# Generate a length n fizzbuzz sequence. # Note the output should be a list of strings. def fizzbuzz(n): return ["1", "2", "Fizz", "4", "Buzz", "6"][:n]
# Generate a length n "Hamming's problem" sequence # where the outputs are all multiples of 2,3, and 5 # in order. def hamming(n): return [1,2,3,4,5,6,8,9,10,12,15][:n]
print(translate("ATGC")) print(get_params(" atoms = 100 ")) print(newton(1.0, 0.0, 1.0, 0.3, 0.1)) assert len(fizzbuzz(5)) == 5 assert len(hamming(8)) == 8
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started