Question

def is_even(value: int) -> bool: """Return True if and only if value is an even number....

def is_even(value: int) -> bool:
"""Return True if and only if value is an even number.
  
>>> is_even(108)
True
>>> is_even(135)
False
"""


def convert_time(hour: int) -> int:
"""Return the given time in hours hour from the 24 hour clock to
a time in hours for the 12 hour clock.

Precondition: 0 <= hour <= 23

>>> convert_time(0)
12
>>> convert_time(4)
4
>>> convert_time(15)
3
"""

Homework Answers

Answer #1
# function to return true if number is even
def is_even(num):
    # if number is even we return true
    if num % 2 == 0:
        return True
    # else we return false
    return False


# function to convert hours in 24 hour clock to 12 hours clock
def convert_time(hour):
    # check if hours are 0 or 12
    if hour == 0 or hour == 12:
        return 12
    # if hours are greater than 12
    elif hour > 12:
        return hour - 12
    # else hours are less than 12
    else:
        return hour

output:

FOR HELP PLEASE COMMENT

THANK YOU

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
def count_evens(values: List[List[int]]) -> List[int]: """Return a list of counts of even numbers in each of...
def count_evens(values: List[List[int]]) -> List[int]: """Return a list of counts of even numbers in each of the inner lists of values.    >>> count_evens([[10, 20, 30]]) [3] >>> count_evens([[1, 2], [3], [4, 5, 6]]) [1, 0, 2] """   
(In Python) Complete the isPrime() function to take an int and return True if it is...
(In Python) Complete the isPrime() function to take an int and return True if it is a prime number and False if it is not. Note: A prime number is not evenly divisible (meaning, the remainder is not 0) for all numbers smaller than itself (down to 2). For example, if num is 7, then you could test: if 7 remainder 6 is not 0, then if 7 remainder 5 is not 0, then if 7 remainder 4 is not...
#Constructor def tree(label, branches=[]): for branch in branches: assert is_tree(branch) return [label] + list(branches) #Selectors def...
#Constructor def tree(label, branches=[]): for branch in branches: assert is_tree(branch) return [label] + list(branches) #Selectors def label(tree): return tree[0] def branches(tree): return tree[1:] def is_tree(tree): if type(tree) != list or len(tree) < 1: return false return True def is_leaf(tree): return not branches(tree) def print_tree(t, indent=0):    print(' ' * indent + str(label(t))) for b in branches(t): print_tree(b, indent + 1) Write a function that takes in a tree and doubles every value. It should return a new tree. You can...
Implement the following functions in the given code: def random_suit_number(): def get_card_suit_string_from_number(n): def random_value_number(): def get_card_value_string_from_number(n):...
Implement the following functions in the given code: def random_suit_number(): def get_card_suit_string_from_number(n): def random_value_number(): def get_card_value_string_from_number(n): def is_leap_year(year): def get_letter_grade_version_1(x): def get_letter_grade_version_2(x): def get_letter_grade_version_3(x): Pay careful attention to the three different versions of the number-grade-to-letter-grade functions. Their behaviors are subtly different. Use the function descriptions provided in the code to replace the pass keyword with the necessary code. Remember: Parameters contain values that are passed in by the caller. You will need to make use of the parameters that each...
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour...
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour notation. For example, it should convert 14:25 to 2:25 PM. (A) The user provides input as two integers separated by ‘:’. The following function prototype should capture the user inputs as described below: void input(int& hours24, int& minutes); //Precondition: input(hours, minutes) is called with //arguments capable of being assigned values. //Postcondition: // user is prompted for time in 24 hour format: // HH:MM, where...
convert this code to accept int value instead of float values using python. Make sure to...
convert this code to accept int value instead of float values using python. Make sure to follow the same code. do not change the steps and make sure to point to what code you replaced. make sure to have 2 files Method:----------------------- #define a python user difined method def get_float_val (prompt): is_num = False str_val = input (prompt) #prming read for our while #while is_num == False: (ignore this but it works) old school while not is_num: try: value =...
1. Complete a class Clock that represents time on a 24-hour clock, such as 00:00, 15:30,...
1. Complete a class Clock that represents time on a 24-hour clock, such as 00:00, 15:30, or 23:59 ○ Time is measured in hours (00 – 23) and minutes (00 – 59) ○ Times are ordered from 00:00 (earliest) to 23:59 (latest) Complete the first constructor of the class Clock ● It takes two arguments: h and m and creates a new clock object whose initial time is h hours and m minutes ● Test cases: Clock clock1 = new...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort algorithm to sort this list. Fill in this table with each iteration of the loop in the selection sort algorithm. Mark the place from which you are looking for the 'next smallest element'. In this display, the upper numbers are the indices, the lower numbers are in the corresponding positions. Use the several rows provided to show the sequence of steps. 0 1 2...
C++ only: Please implement a function that accepts a string parameter as well as two character...
C++ only: Please implement a function that accepts a string parameter as well as two character arguments and a boolean parameter. Your function should return the number of times it finds the character arguments inside the string parameter. When both of the passed character arguments are found in the string parameter, set the boolean argument to true. Otherwise, set that boolean argument to false. Return -1 if the string argument is the empty string. The declaration for this function will...
Here is a bit of Java code: Thing t = new Thing(); t.method( (int i)-> i...
Here is a bit of Java code: Thing t = new Thing(); t.method( (int i)-> i + 1 ); Here is a skeleton for class Thing: class Thing { public interface Mystery { ????? } public void method( Mystery param ) { // body of method omitted } } Which text below would work where ????? is given above: a) void method( int i ); b) int method( int i ); c) abstract int method( int i ); d) abstract...