Search
def abs_2(x): """Return an absolute value of x-2, i.e., y=|x-2|. :param x: int, float. :return: int, float. The absolute value of x-2. >>> abs_2(0) 2 """
abs_2()
def abs_2_list(lst): """Return a list of absolute values of x-2, where x's are elements of lst. :param lst: list of ints/floats. :return: list of ints/floats. >>> abs_2_list([0, 2, 4]) [2, 0, 2] """
number_file.txt
1,2,3,4 90,23,78,0,23,23 9,8,7,-5,-12,0,12,12,12 0,-8 3,3,3,3
def sum_file(file_name): """Return a list of row sums. :param file_name: Path to a text file. :return: list of ints/floats. >>> sum_file("number_file.txt") [10, 237, 43, -8, 12] """
import unittest class ColorRGB: """Represents a color in the R (red), G (green), B (blue) format.""" class TestColorRGB(unittest.TestCase): """Test ColorRGB methods""" def test_init(self): """Test that the initializer method __init__ takes 3 parameters""" ColorRGB(255, 0, 255) def test_str(self): """Test string conversion""" self.assertEqual("ColorRGB(0,127,127)", str(ColorRGB(0, 127, 127))) def test_eq(self): """Test deep equality for two ColorRGB instances""" self.assertEqual(ColorRGB(0,30,255), ColorRGB(0,30,255)) def test_add(self): """Test the plus operator between two instances of the ColorRGB class""" color1 = ColorRGB(30, 100, 255) color2 = ColorRGB(0, 255, 30) self.assertEqual(ColorRGB(30, 255, 255), color1 + color2) self.assertEqual(ColorRGB(30, 100, 255), color1) self.assertEqual(ColorRGB(0, 255, 30), color2) if __name__ == "__main__": # Execute all unit tests unittest.main()
def random_integers(length, lower_bound, upper_bound): """Build a list of randomly chosen integers. :param length: Length of the resulting list :param lower_bound: Lower bound of each random integer (INCLUDED) :param upper_bound: Upper bound of each random integer (INCLUDED) :return: List of random integers """
# 1. fruits = ["apple", "banana", "pear", "kiwi", "strawberry", "lime", "lemon", "orange"] # only words of even number of letters, transform them to uppercase # 2. # List of |x-2| where x's are all integers in the closed interval [-10, 10].