User Tools

Site Tools


assignment2key

This is an old revision of the document!


Assignment 2 Answer Key

assignment2.py
#Exercise 1
 
def nt_id(seq):
	if 'U' in seq:
		return 'RNA'
	elif 'T' in seq:
		return 'DNA'
	else:
		return 'unk'
 
 
# Exercise 2
 
def stop_codon(seq):
	if 'UGA' in seq or 'UAA' in seq or 'UAG' in seq :
		return True
	else:
		return False
 
 
# Exercise 3
 
def peptide_length(seq):
	return len(seq) // 3
 
 
# Exercise 4
 
def cube_root(n):
	try:
		return float(n)**(1/3)
	except:
		return 'Invalid entry'
 
 
# Exercise 5
 
def sum_num(n1 = 0, n2 = 0, n3 = 0, n4 = 0):
	return n1 + n2 + n3 + n4
 
 
# This code is used for testing each of the functions
if __name__ == '__main__': 
 
#	seq = input('Enter a sequence: ') # input for exercises 1-3
# 	num = input('Enter a number: # input for exercises 4
#	print(sum_num(5,6,7)) # no input prompt for exercise 5
 
# 	print(nt_id(seq))
# 	print(stop_codon(seq))
# 	print(peptide_length(seq))
# 	print(cube_root(num))
 
 
# Exercise 6:  should be written as a separate script
 
import assignment2
if assignment2.stop_codon(input('Enter an RNA sequence: ')) == True:
	print('The sequence contains a stop codon.')
else:
	print('The sequence does not contain a stop codon.')
assignment2key.1539214541.txt.gz · Last modified: 2018/10/10 17:35 by dokuroot