Learn to Program: The Fundamentals Assignment 2 Solution

In this article i am gone to share a Coursera Course: Learn to Program: The Fundamentals Week Assignment | Programming Assignment: Assignment 2 Solution with you..

What to do

There are several functions that you will need to implement. We have listed the functions roughly in order of complexity. Each function body will be quite short. You can submit your assignment for feedback once every hour up until the deadline; we recommend that you do this at least once early on in order to make sure you can submit properly.

Step 1: Download the starter code
Step 2: Complete the body of function seconds_difference
Step 3: Complete the body of function hours_difference
Step 4: Complete the body of function to float_hours
Step 5: Write functions get_hours, get_minutes and get_seconds
Step 6: Complete the bodies of functions time_to_utc and time_from_utc
Step 7: Submit your work.

Learn to Program: The Fundamentals Assignment 2 Solution

You first need to create a python file give name assignment1.py
Copy all the code paste in a file and then save it.
Now upload your file on Coursera Course assignment and then click on submit.


def get_length(dna):
“”” (str) -> int

Return the length of the DNA sequence dna.

>>> get_length(‘ATCGAT’)
>>> get_length(‘ATCG’)
return len(dna)

def is_longer(dna1, dna2):
“”” (str, str) -> bool

Return True if and only if DNA sequence dna1 is longer than DNA sequence

>>> is_longer(‘ATCG’, ‘AT’)
>>> is_longer(‘ATCG’, ‘ATCGGA’)
return (len(dna1)>len(dna2))

def count_nucleotides(dna, nucleotide):
“”” (str, str) -> int

Return the number of occurrences of nucleotide in the DNA sequence dna.

>>> count_nucleotides(‘ATCGGC’, ‘G’)
>>> count_nucleotides(‘ATCTA’, ‘G’)
count = 0
for char in dna:
if (char == nucleotide):
count = count +1
return count

def contains_sequence(dna1, dna2):
“”” (str, str) -> bool

Return True if and only if DNA sequence dna2 occurs in the DNA sequence

>>> contains_sequence(‘ATCGGC’, ‘GG’)
>>> contains_sequence(‘ATCGGC’, ‘GT’)

return (dna2 in dna1)

def is_valid_sequence(dna):
“”” (str) -> bool

The parameter is a potential DNA sequence.
Return True if and only if the DNA sequence
is valid (that is, it contains no characters
other than ‘A’, ‘T’, ‘C’ and ‘G’).

>>> is_valid_sequence(“ATCGCGTAT”)
>>> is_valid_sequence(“ATCGCHGTAT”)

count = True

for char in dna:
if char not in “ATCG”:
count = False

return count

def insert_sequence(dna1, dna2, i):
“”” (str, str, int) -> str

The first two parameters are DNA sequences
and the third parameter is an index.
Return the DNA sequence obtained by inserting the
second DNA sequence into the first DNA sequence
at the given index. (You can assume that the index is valid.)

>>> insert_sequence(“ATCA”, “CGCG”, 3)
>>> insert_sequence(“ATCA”, “CGCG”, 0)


dna = “”
dna = dna1[:i] + dna2 + dna1[i:]
return dna

def get_complement(n):
“”” (str) -> str

The first parameter is a nucleotide
(‘A’, ‘T’, ‘C’ or ‘G’). Return the nucleotide’s complement.

>>> get_complement(‘A’)
>>> get_complement(‘T’)
>>> get_complement(‘C’)
>>> get_complement(‘G’)


if (n == ‘A’):
return ‘T’
elif (n == ‘T’):
return ‘A’
elif (n == ‘C’):
return ‘G’
return ‘C’

def get_complementary_sequence(dna):
“”” (str) -> str

The parameter is a DNA sequence.
Return the DNA sequence that is complementary
to the given DNA sequence.

>>> get_complementary_sequence(“ATCGAT”)
>>> get_complementary_sequence(“CCCGTTTATCGA”)


seq = “”
for char in dna:
if (char == “A”):
seq = seq + “T”
elif (char == ‘T’):
seq = seq + “A”
elif (char == “C”):
seq = seq + “G”
seq = seq + “C”

return seq

Note: after submit please wait your marks will we updated within 2 minutes.. If you get any error tell me i will resolved it.. Thank you..

Leave a Comment