Learn to Program The Fundamentals | Week(1-7) & Final | Coursera Answers 2024

Course Name – Learn to Program The Fundamentals

Platform – Coursera

Course Enroll Link – https://www.coursera.org/learn/learn-to-program

Learn to Program The Fundamentals

Here we will provide answers to all the Weeks ( 1-7 ), Final, and Assignments of the “Learn to Program The Fundamentals” course of the Coursera platform.

Please Note: We tried our best to maintain this site updated to our customers for free. You may even contribute by upgrading brand new questions or present question-answers. You’ll find several questions on our site; it isn’t easy for all of us to assess them regularly. It’s going to be great when you will help us to upgrade the website. Discuss the same Answer submit or page or contact page. We’ll attempt to upgrade the question/answer immediately.

Learn to Program The Fundamentals | Week(1-7) & Final | Coursera Answers

Watch The Video To Get All The Answers
Learn to Program The Fundamentals | Week(1-7) & Final | Coursera Answers

Assignment 1: Time Zones

def seconds_difference(time_1, time_2):
    """ (number, number) -> number
    Return the number of seconds later that a time in seconds
    time_2 is than a time in seconds time_1.
        
    >>> seconds_difference(1800.0, 3600.0)
    1800.0
    >>> seconds_difference(3600.0, 1800.0)
    -1800.0
    >>> seconds_difference(1800.0, 2160.0)
    360.0
    >>> seconds_difference(1800.0, 1800.0)
    0.0
    """
    
    return time_2 - time_1

def hours_difference(time_1, time_2):
    """ (number, number) -> float
    Return the number of hours later that a time in seconds
    time_2 is than a time in seconds time_1.
        
    >>> hours_difference(1800.0, 3600.0)
    0.5
    >>> hours_difference(3600.0, 1800.0)
    -0.5
    >>> hours_difference(1800.0, 2160.0)
    0.1
    >>> hours_difference(1800.0, 1800.0)
    0.0
    """

    return ((time_2 - time_1) / 60) / 60

def to_float_hours(hours, minutes, seconds):
    """ (int, int, int) -> float
    Return the total number of hours in the specified number
    of hours, minutes, and seconds.
    Precondition: 0 <= minutes < 60  and  0 <= seconds < 60
    >>> to_float_hours(0, 15, 0)
    0.25
    >>> to_float_hours(2, 45, 9)
    2.7525
    >>> to_float_hours(1, 0, 36)
    1.01
    """

    return hours + (minutes / 60) + (seconds / 60 / 60)

def to_24_hour_clock(hours):
    """ (number) -> number
    hours is a number of hours since midnight. Return the
    hour as seen on a 24-hour clock.
    Precondition: hours >= 0
    >>> to_24_hour_clock(24)
    0
    >>> to_24_hour_clock(48)
    0
    >>> to_24_hour_clock(25)
    1
    >>> to_24_hour_clock(4)
    4
    >>> to_24_hour_clock(28.5)
    4.5
    """

    return hours % 24



### Write your get_hours function definition here:

def get_hours(seconds):
    """ (number) -> number
    Return the number of hours equivelant to seconds.
        
    >>> get_hours(3800)
    1
    >>> get_hours(7600)
    2
    >>> get_hours(2400)
    0
    >>> get_hours(3600)
    1
    """
    
    return to_24_hour_clock(seconds // 3600)


### Write your get_minutes function definition here:

def get_minutes(seconds):
    """ (number) -> number
    Return the remainder of seconds remaining and convert to minutes.
    
    >>> get_minutes(3800)
    3
    >>> get_minutes(7600)
    6
    >>> get_minutes(3600)
    0
    """

    return (seconds % 3600) // 60 


### Write your get_seconds function definition here:

def get_seconds(seconds):
    """ (number) -> number
    Return the remainder of seconds remaining and convert to minutes.
    
    >>> get_seconds(3800)
    20
    >>> get_seconds(7600)
    40
    >>> get_seconds(3600)
    0 
    """

    return (seconds % 3600) % 60 


def time_to_utc(utc_offset, time):
    """ (number, float) -> float
    Return time at UTC+0, where utc_offset is the number of hours away from
    UTC+0.
    >>> time_to_utc(+0, 12.0)
    12.0
    >>> time_to_utc(+1, 12.0)
    11.0
    >>> time_to_utc(-1, 12.0)
    13.0
    >>> time_to_utc(-11, 18.0)
    5.0
    >>> time_to_utc(-1, 0.0)
    1.0
    >>> time_to_utc(-1, 23.0)
    0.0
    >>> time_to_utc(-1, .5)
    23.5
    """

    return to_24_hour_clock(time - utc_offset)

def time_from_utc(utc_offset, time):
    """ (number, float) -> float
    Return UTC time in time zone utc_offset.
    >>> time_from_utc(+0, 12.0)
    12.0
    >>> time_from_utc(+1, 12.0)
    13.0
    >>> time_from_utc(-1, 12.0)
    11.0
    >>> time_from_utc(+6, 6.0)
    12.0
    >>> time_from_utc(-7, 6.0)
    23.0
    >>> time_from_utc(-1, 0.0)
    23.0
    >>> time_from_utc(-1, 23.0)
    22.0
    >>> time_from_utc(+1, 23.0)
    0.0
    >>> time_to_utc(-1, .5)
    1.5
    """

    return to_24_hour_clock(time + (utc_offset))

Assignment 2:DNA Processing

def get_length(dna):
    ''' (str) -> int
    Return the length of the DNA sequence dna.
    >>> get_length('ATCGAT')
    6
    >>> get_length('ATCG')
    4
    '''

    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
    dna2.
    >>> is_longer('ATCG', 'AT')
    True
    >>> is_longer('ATCG', 'ATCGGA')
    False
    '''
    return dna1 > 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')
    2
    >>> count_nucleotides('ATCTA', 'G')
    0
    '''
    return dna.count(nucleotide)

def contains_sequence(dna1, dna2):
    ''' (str, str) -> bool
    Return True if and only if DNA sequence dna2 occurs in the DNA sequence
    dna1.
    >>> contains_sequence('ATCGGC', 'GG')
    True
    >>> contains_sequence('ATCGGC', 'GT')
    False
    
    '''
    return dna2 in dna1

def is_valid_sequence(dna):
    '''(str) -> bool
    Return true if and only if the DNA sequence is valid. The sequence must
    only contain the characters 'A', 'T', 'C', and 'G'. Lower case characters
    are not valid.
    >>> is_valid_sequence('ATCG')
    True
    >>> is_valid_sequence('AAGCTT')
    True
    >>> is_valid_sequence('ATcG')
    False
    >>> is_valid_sequence('CTGAX')
    False
    '''
    
    num_nucleotides = True
    
    for char in dna:
        if char in 'BDEFHIJKLMNOPQRSUVWXYZabcdefghijklmnopqrstuvwxyz':
            num_nucleotides = False
            
    return num_nucleotides


def insert_sequence(dna1, dna2, num):
    '''(str, str, int) -> str
     Return the DNA sequence obtained by inserting dna2 into dna1 at the
     given index of num.
    >>> insert_sequence('CCGG', 'AT', 2)
    'CCATGG'
    >>> insert_sequence('ATCTAGCC', 'CAT', 5)
    'ATCTACATGCC'
    >>>insert_sequence('ATGGC', 'TA', 1)
    'ATATGGC'
    '''
    
    return dna1[:num] + dna2 + dna1[num:]


def get_complement(nucleotide):
    '''(str) -> str
    Return the nucletides complement.
    Precondition A complements T, C compliments G
    >>> get_complement('A')
    'T'
    >>> get_complement('C')
    'G'
    >>> get_complement('T')
    'A'
    '''

    if nucleotide == 'A':
       return 'T'
    elif nucleotide == 'T':
        return 'A'
    elif nucleotide == 'C':
        return 'G'
    elif nucleotide == 'G':
        return 'C'

def get_complementary_sequence(dna):

    '''(str) -> str
    Return the DNA sequence that is complimentary to the given
    DNA sequence.
    Precondition A complements T, C complements G
    >>> get_complementary_sequence('AT')
    'TA'
    >>> get_complementary_sequence('TAGC')
    'ATCG'
    >>> get_complementary_sequence('ATCGA')
    'TAGCT'
    '''
    dna_complement = ''
    
    for char in dna:
        if char in 'ATCG':
            dna_complement = dna_complement + get_complement(char)
    return dna_complement

Assignment 3

"""A board is a list of list of str. For example, the board
    ANTT
    XSOB
is represented as the list
    [['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']]

A word list is a list of str. For example, the list of words
    ANT
    BOX
    SOB
    TO
is represented as the list
    ['ANT', 'BOX', 'SOB', 'TO']
"""


def is_valid_word(wordlist, word):
    """ (list of str, str) -> bool

    Return True if and only if word is an element of wordlist.

    >>> is_valid_word(['ANT', 'BOX', 'SOB', 'TO'], 'TO')
    True
    """
   
    i = 0
    while i < len(wordlist):
        return word in wordlist
        i = i + 1


def make_str_from_row(board, row_index):
    """ (list of list of str, int) -> str

    Return the characters from the row of the board with index row_index
    as a single string.

    >>> make_str_from_row([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], 0)
    'ANTT'
    """

    word = ''
    i = row_index
    for char in board[i]:
        word = word + char
    return word


def make_str_from_column(board, column_index):
    """ (list of list of str, int) -> str

    Return the characters from the column of the board with index column_index
    as a single string.

    >>> make_str_from_column([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], 1)
    'NS'
    """

    word = ''
    i = column_index
    for char in board:
        word =  word + (char[i])
    return word


def board_contains_word_in_row(board, word):
    """ (list of list of str, str) -> bool    Return True if and only if one or more of the rows of the board contains word.

    Precondition: board has at least one row and one column, and word is a valid word.

    >>> board_contains_word_in_row([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], 'SOB')
    True
    """

    for row_index in range(len(board)):
        if word in make_str_from_row(board, row_index):
            return True

    return False


def board_contains_word_in_column(board, word):
    """ (list of list of str, str) -> bool

    Return True if and only if one or more of the columns of the board contains word.

    Precondition: board has at least one row and one column, and word is a valid word.

    >>> board_contains_word_in_column([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], 'NO')
    False
    """

    i = 0
    while i < len(board[0]):
        if word in make_str_from_column(board, i):
            return True
        i = i + 1
       
    return False


def board_contains_word(board, word):
    """ (list of list of str, str) -> bool

    Return True if and only if word appears in board.

    Precondition: board has at least one row and one column.

    >>> board_contains_word([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], 'ANT')
    True
    """

    a = board_contains_word_in_row(board, word)
    b = board_contains_word_in_column(board, word)
    if a or b:
        return True
    return False


def word_score(word):
    """ (str) -> int

    Return the point value the word earns.

    Word length: < 3: 0 points                 3-6: 1 point per character for all characters in word
                 7-9: 2 points per character for all characters in word
                 10+: 3 points per character for all characters in word

    >>> word_score('DRUDGERY')
    16
    """

    score = len(word)
    if score < 3:
        return score*0
    elif score >=3 and score <=6:
        return score*1
    elif score >=7 and score <=9:
        return score*2
    elif score >=10:
        return score*3
    return score


def update_score(player_info, word):
    """ ([str, int] list, str) -> NoneType

    player_info is a list with the player's name and score. Update player_info
    by adding the point value word earns to the player's score.

    >>> update_score(['Jonathan', 4], 'ANT')
    """

    current_point = player_info.pop(1)
    point = current_point + word_score(word)
    player_info.append(point)
   

def num_words_on_board(board, words):
    """ (list of list of str, list of str) -> int

    Return how many words appear on board.

    >>> num_words_on_board([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], ['ANT', 'BOX', 'SOB', 'TO'])
    3
    """

    count = 0
    for word in words:
        if board_contains_word(board, word):
            count = count + 1
    return count


def read_words(words_file):
    """ (file open for reading) -> list of str

    Return a list of all words (with newlines removed) from open file
    words_file.

    Precondition: Each line of the file contains a word in uppercase characters
    from the standard English alphabet.
    """

    lists = []
   
   
   
    for line in words_file:
        word = ''

        for char in line:
           
            if char != '\n':
                word = word + char

        lists.append(word)

    return lists


def read_board(board_file):
    """ (file open for reading) -> list of list of str

    Return a board read from open file board_file. The board file will contain
    one row of the board per line. Newlines are not included in the board.
    """

    lists = []
         
    for line in board_file:
       
        #Append characters into sublist
        sub = []
        for char in line:
           
            if char != '\n':
                sub.append(char)

        if sub != []:
            lists. append(sub)

    return lists

Share on:
Online Certification Guide

About Author

Hey there, its OnlineCertificationGuide here to help you out in your Journey in the study. So my friend share the site with your friends in case I am helpful to you.

3 thoughts on “Learn to Program The Fundamentals | Week(1-7) & Final | Coursera Answers 2024”

  1. Hi there! I could have sworn I’ve been to this web site before but after going through some of the posts I realized it’s new to me. Nonetheless, I’m definitely delighted I stumbled upon it and I’ll be bookmarking it and checking back frequently!

  2. After I initially left a comment I seem to have clicked the -Notify me when new comments are added- checkbox and now whenever a comment is added I get 4 emails with the same comment. There has to be a means you are able to remove me from that service? Kudos!|

  3. You’re so cool! I don’t believe I have read something like that before. So wonderful to find someone with some original thoughts on this subject. Seriously.. thanks for starting this up. This web site is something that is required on the web, someone with a bit of originality!|

Comments are closed.