$29.99
Assignment #1
The following assignment is a collection of exercises meant to help you understand and use basic datatypes.
1. A. In the string class, find two string methods that will returns True if the string can be converted into
an integer. (5 points)
e.g.
>>> a = '23432'
>>> [Your code]
True
>>> [Your code]
True
>>> a = '23423.234'
>>> [Your code]
False
>>> [Your code]
False
>>> a = 'PatrickMcGrath'
>>> [Your code]
False
>>> [Your code]
False
B. Using Google, determine what the difference is between these two methods. (5 points)
2. Sometimes you want to pad a string so that it’s a certain length. For example, let’s say you have a DNA
sequence that you wanted to be 9 bp long, adding ‘N’s for any bases that are missing. Find two
methods that would allow you to do the following: (5 points for each)
>>> b
'CGTTT'
>[Your code]
'CGTTT----'
>[Your code]
'----CGTTT'
3. Assume you have a float, 3454.4521. You want to split this number into the integer and decimal portion
of the number. (5 points for each)
A. In the first case, just use methods or magic methods of the float class to accomplish this. E.g.:
>>> a = 3454.4521
>>> [Your code]
3454
>>> [Your code]
0.4520999999999731
B. Convert the float to a string and use string methods to accomplish this (the final numbers should be
integers)
>>> b = str(a)
>>> b
'3454.4521'
>>> [Your code]
4. Create a function that takes in three numbers and returns the sum (10 points)
5. Create a function that takes in a string containing 10 words separated by commas and returns a list of
the words in alphabetical order (10 points)
6. a = True
A. What kind of object is a? (4 points)
B. What kind of object is returned by a + a? (3 points)
C. What type of object is returned by a * a? (3 points)
7. Assume you have a string of valid DNA sequence (all upper case). DNA methylation enzymes can add
methyl groups to DNA nucleotides at defined sequences. However, there can be redundancy in the
motif recognized by the protein. For example, the CcrM methyltransferase recognizes GANTC sites
(where N can be any of the four nucleotides). Create a single line that returns the number of CcrM
methylation sites within the string of DNA sequence (call the variable DNA_sequnce). (10 points)
>>> seq = 'AGAAGGCCCTAGAGTCCAAGACTCAGATTCAGAATCGACTC'
>>> [Your code here]
5
8. You are asked to take a of DNA sequence and return a string of RNA sequence by replacing all the Ts
with Us. Do this in two ways:
A. Use a single string method to accomplish this (5 points)
B. Use a combination of string’s split and join methods to accomplish this (5 points)
9. There are four points to this question (2.5 points each)
A. Create a list of numbers between 1 and 15
B. Use a list comprehension to convert the numbers to strings and add a letter x in front of each
C. Use a string method to concatenate the list into a single string separated by two periods
D. Chain all of these commands together into a single line that accomplishes all three tasks
>>> a = [Your code]
>>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
>>> b = [Your code]
>>> b
['x0', 'x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x7', 'x8', 'x9', 'x10', 'x11', 'x12', 'x13', 'x14']
>>> c = [Your code]
>>> c
'x0..x1..x2..x3..x4..x5..x6..x7..x8..x9..x10..x11..x12..x13..x14'
>>> [Your code]
'x0..x1..x2..x3..x4..x5..x6..x7..x8..x9..x10..x11..x12..x13..x14'
10. You are given a list of tasks by your professor:
A. Sort the list in alphabetical order (2.5 points).
B. You are given a string representing an additional single task. Add this task to the beginning of the list.
C. Add this task to the end of the list.
D. You are now given a new list of tasks. Add these tasks to the list of tasks
>>> tasks = ['Read Lecture', 'Go to class', 'Work on homework']
>>> [Your code]
>>> tasks
['Go to class', 'Read Lecture', 'Work on homework']
>>> new_task = 'Start computer'
>>> [Your code]
>>> tasks
['Start computer', 'Go to class', 'Read Lecture', 'Work on homework']
>>> tasks.pop(0)
'Start computer'
>>> tasks
['Go to class', 'Read Lecture', 'Work on homework']
>>> [Your code]
>>> tasks
['Go to class', 'Read Lecture', 'Work on homework', 'Start computer']
>>> new_tasks = ['Study', 'Check grade']
>>> [Your code]
>>> tasks
['Go to class', 'Read Lecture', 'Work on homework', 'Start computer', 'Study', 'Check grade']