Question

In: Computer Science

def warmer_year(temps_then: List[int], temps_now: List[int]) -> List[str]: """Return a list of strings representing whether this year's...

def warmer_year(temps_then: List[int], temps_now: List[int]) -> List[str]:
"""Return a list of strings representing whether this year's
temperatures from temps_now are warmer than past temperatures
in temps_then. The resulting list should contain "Warmer" at the
indexes where this year's temperature is warmer, and "Not Warmer"
at the indexes where the past year was warmer, or there is a tie.

Precondition: len(temps_then) == len(temps_now)

>>> warmer_year([10], [11])
['Warmer']
>>> warmer_year([26, 27, 27, 28], [25, 28, 27, 30])
['Not Warmer', 'Warmer', 'Not Warmer', 'Warmer']
"""

## complete the function here

Solutions

Expert Solution

from typing import *


def warmer_year(temps_then: List[int], temps_now: List[int]) -> List[str]:
    """Return a list of strings representing whether this year's
    temperatures from temps_now are warmer than past temperatures
    in temps_then. The resulting list should contain "Warmer" at the
    indexes where this year's temperature is warmer, and "Not Warmer"
    at the indexes where the past year was warmer, or there is a tie.

    Precondition: len(temps_then) == len(temps_now)

    >>> warmer_year([10], [11])
    ['Warmer']
    >>> warmer_year([26, 27, 27, 28], [25, 28, 27, 30])
    ['Not Warmer', 'Warmer', 'Not Warmer', 'Warmer']
    """
    result = []
    for i in range(len(temps_now)):
        if temps_now[i] > temps_then[i]:
            result.append('Warmer')
        else:
            result.append('Not Warmer')
    return result


# Testing the function here. ignore/remove the code below if not required
print(warmer_year([10], [11]))
print(warmer_year([26, 27, 27, 28], [25, 28, 27, 30]))


Related Solutions

from typing import List def longest_chain(submatrix: List[int]) -> int: """ Given a list of integers, return...
from typing import List def longest_chain(submatrix: List[int]) -> int: """ Given a list of integers, return the length of the longest chain of 1's that start from the beginning. You MUST use a while loop for this! We will check. >>> longest_chain([1, 1, 0]) 2 >>> longest_chain([0, 1, 1]) 0 >>> longest_chain([1, 0, 1]) 1 """ i = 0 a = [] while i < len(submatrix) and submatrix[i] != 0: a.append(submatrix[i]) i += 1 return sum(a) def largest_rectangle_at_position(matrix: List[List[int]], x:...
Why is 1 example of my code failing? def current_player_score(score_one: int, score_two: int,current_player: str) -> int:...
Why is 1 example of my code failing? def current_player_score(score_one: int, score_two: int,current_player: str) -> int: """Return <score_one> if the <current_player> represents player one, or <score_two> if the <current_player> represents player two. >>> current_player_score(2, 4, "Player one") 2 >>> current_player_score(2, 3, "Player two") 3 """ if current_player == PLAYER_ONE: return score_one return score_two
r = range(10, 40, 3) def print_lv(strings): strings = strings if isinstance(strings, list) else [strings] for...
r = range(10, 40, 3) def print_lv(strings): strings = strings if isinstance(strings, list) else [strings] for string in strings: st = "f'" + string + ": {" + string + "}'" print_stmt = 'print(' + st + ', end="; ")' # Uncomment the following print statement to see the statement to be executed. # Each will appear on a separate line. # print(f'\n{print_stmt}') exec(print_stmt) print() print_lv(['list(r)', 'r[-2:3:-1]', 'list(r[-2:3:-1])']) OUTPUT: list(r): [10, 13, 16, 19, 22, 25, 28, 31, 34, 37];...
def largest_rectangle_in_matrix(matrix: List[List[int]]) -> int: """ Returns the area of the largest rectangle in <matrix>. The...
def largest_rectangle_in_matrix(matrix: List[List[int]]) -> int: """ Returns the area of the largest rectangle in <matrix>. The area of a rectangle is defined as the number of 1's that it contains. Again, you MUST make use of <largest_rectangle_at_position> here. If you managed to code largest_rectangle_at_position correctly, this function should be very easy to implement. Similarly, do not modify the input matrix. Precondition: <matrix> will only contain the integers 1 and 0. >>> case1 = [[1, 0, 1, 0, 0], ... [1,...
SIGN_GROUPS = '[ARI,LEO,SAG]-[TAU,VIR,CAP]-[GEM,LIB,AQU]-[PIS,SCO,CAN]' def get_sign_group(sign): ''' (str) -> int Given a three character string representing a...
SIGN_GROUPS = '[ARI,LEO,SAG]-[TAU,VIR,CAP]-[GEM,LIB,AQU]-[PIS,SCO,CAN]' def get_sign_group(sign): ''' (str) -> int Given a three character string representing a star sign, return which group (out of 0, 1, 2, or 3) this star sign belongs to. Use the SIGN_GROUPS string (already defined for you above) to figure out the group. i.e. As given by this string '[ARI,LEO,SAG]-[TAU,VIR,CAP]-[GEM,LIB,AQU]-[PIS,SCO,CAN]' the signs ARI, LEO and SAG are in group 0, the signs TAU, VIR, CAP are in group 1, and so on. >>> get_sign_group('ARI') 0 >>>...
Can you tell me what is wrong with this code ? def update_char_view(phrase: str, current_view: str,...
Can you tell me what is wrong with this code ? def update_char_view(phrase: str, current_view: str, index: int, guess: str)->str: if guess in phrase: current_view = current_view.replace(current_view[index], guess) else: current_view = current_view    return current_view update_char_view("animal", "a^imal" , 1, "n") 'animal' update_char_view("animal", "a^m^l", 3, "a") 'aamal'
from partition import partition def quicksort(a: list, l: int, u: int) -> None: '''Sort the given...
from partition import partition def quicksort(a: list, l: int, u: int) -> None: '''Sort the given list a in non-descending order. Precondition: 0 <= l and u < len(a)''' if l < u: mid = (l + u) // 2 three = [a[l], a[mid], a[u]] three.sort() if three[1] == a[l]: pivot_loc = l elif three[1] == a[u]: pivot_loc = u else: pivot_loc = mid a[u], a[pivot_loc] = a[pivot_loc], a[u] pivot = a[u] i = partition(a, l, u - 1, pivot)...
def num_to_digit_rec(num, base): """ Return a list of digits for num with given base; Return an...
def num_to_digit_rec(num, base): """ Return a list of digits for num with given base; Return an empty list [] if base < 2 or num <= 0 """ # Write your code here return [] def digit_sum(num, base): """ Return the sum of all digits for a num with given base Your implementation should use num_to_digit_rec() function """ # Write your code here return 0 def digit_str(num, base): """ Given a number and a base, for base between [2, 36]...
Python 3.7.4 Costume = {'label': str, 'price': int, 'sizes': [str]} ''' C5. Define a function `most_expensive_costume`...
Python 3.7.4 Costume = {'label': str, 'price': int, 'sizes': [str]} ''' C5. Define a function `most_expensive_costume` that consumes a list of costumes and produces a string representing the label of the costume with the highest price. In the event of a tie, give the label of the item later in the list. If there are no costumes, return the special value None. ''' ''' C6. Define a function `find_last_medium` that consumes a list of costumes and produces the label of...
Qno.1 Part(A). IN jAVA if 1.Int abc; 2. Int def = 8; 3. abc = def;...
Qno.1 Part(A). IN jAVA if 1.Int abc; 2. Int def = 8; 3. abc = def; ➢ Describe the procedure how much memory will be allocated when these three lines of codes will execute. ➢ Describe what will happened after execution of each of these line of code in term of memory allocation and data storage Qno.1 Part(B) A capacitor is constructed from two conductive metal plates 30cm x 50cm which are spaced 6mm apart from each other, and uses...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT