# Assignment #1 Basic datatypes

Original price was: \$35.00.Current price is: \$30.00.

Category:
Rate this product

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’
True
True
>>> a = ‘23423.234’
False
False
>>> a = ‘PatrickMcGrath’
False
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’
‘CGTTT—-‘
‘—-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
3454
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’
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’
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
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
>>> b
[‘x0’, ‘x1’, ‘x2’, ‘x3’, ‘x4’, ‘x5’, ‘x6’, ‘x7’, ‘x8’, ‘x9’, ‘x10’, ‘x11’, ‘x12’, ‘x13’, ‘x14’]
>>> c
‘x0..x1..x2..x3..x4..x5..x6..x7..x8..x9..x10..x11..x12..x13..x14’
‘x0..x1..x2..x3..x4..x5..x6..x7..x8..x9..x10..x11..x12..x13..x14’
A. Sort the list in alphabetical order (2.5 points).
[‘Go to class’, ‘Read Lecture’, ‘Work on homework’]
[‘Start computer’, ‘Go to class’, ‘Read Lecture’, ‘Work on homework’]
‘Start computer’
[‘Go to class’, ‘Read Lecture’, ‘Work on homework’]