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:...
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];...
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)...
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...
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...
from PIL import Image def stringToBits(string):     return str(bin(int.from_bytes(string.encode(), 'big')))[2:] def bitsToString(bits):     if bits[0:2] != '0b':         bits.
from PIL import Image def stringToBits(string):     return str(bin(int.from_bytes(string.encode(), 'big')))[2:] def bitsToString(bits):     if bits[0:2] != '0b':         bits = '0b' + bits     value = int(bits, 2)     return value.to_bytes((value.bit_length() + 7) // 8, 'big').decode() def writeMessageToRedChannel(file, message):     image = Image.open(file)     width, height = image.size     messageBits = stringToBits(message)     messageBitCounter = 0     y = 0     while y < height:         x = 0         while x < width:             r, g, b, a = image.getpixel((x, y))             print("writeMessageToRedChannel: Reading pixel %d, %d - Original values (%d, %d, %d, %d)"...
Recall the is_hour(str) and is_minute(str) functions return True if the str contains valid hour and minute respectively
Recall the is_hour(str) and is_minute(str) functions return True if the str contains valid hour and minute respectively. That is, is_hour("03:65") would return True and is_minute("03:65") would return False.For each of the following expression, indicate whether short-circuit evaluation would occur. That is, the function call on the LHS of the logic operator would not actually be evaluated.ExpressionShort-circuit evaluationExpressionShort-circuit evaluationis_hour("03:65") and is_minute("03:65")--YesNois_hour("03:65") or is_minute("03:65"--YesNois_minute("03:65") and is_hour("03:65")--YesNois_minute("03:65") and is_hour("03:65")--YesNo
class employee: name = str('')    hourlyWage=0 hoursWorked=0 def getPayment(self): payment=self.hourlyWage*self.hoursWorked return payment    class payrollApp(employee):...
class employee: name = str('')    hourlyWage=0 hoursWorked=0 def getPayment(self): payment=self.hourlyWage*self.hoursWorked return payment    class payrollApp(employee):    def printStatement(self): print('The Employee Name is ' + self.name) print('The Employee Hourly wage is ' + str(self.hourlyWage)) print('No of hours worked ' + str(self.hoursWorked)) print('The Employee payment is ' + str(employee.getPayment(self))) emp = [] x=0 a=True totalPayout=0 while a:    emp.append(payrollApp()) emp[x].name=input("Enter Employee Name: ") emp[x].hourlyWage=int(input("Enter hourly wage: ")) emp[x].hoursWorked=int(input("Enter No of hours worked: ")) totalPayout= totalPayout + (emp[x].hourlyWage * emp[x].hoursWorked) print("\n") x=x+1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT