Write your code: Largest Number#

Write functions that returns:

  • the largest number of 3;

  • the largest in a list of any size.

Function definition: The largest number of 3#

Complete the function bellow so that it returns the largest number between x, y and z.

def get_largest(x, y, z):

    # write the code here
  File "/tmp/ipykernel_2235/4212442102.py", line 3
    # write the code here
                         ^
SyntaxError: unexpected EOF while parsing

Testing: The largest number of 3#

Check if your function returns the expected value using the cell below.

import unittest

class UnitTests(unittest.TestCase):
    def test_type(self):
        self.assertEqual(type(get_largest(100, 1, 2)), type(100), 'The function should return an integer.')    
    def test_first(self):
        self.assertEqual(get_largest(100, 1, 2), 100, 'The function should return 100')
    def test_second(self):
        self.assertEqual(get_largest(1, 100, 2), 100, 'The function should return 100')
    def test_third(self):
        self.assertEqual(get_largest(1, 2, 100), 100, 'The function should return 100')
        
unittest.main(argv=[''], verbosity=2,exit=False)

Function definition: The largest in a list#

Complete the function bellow so that it returns the largest number in the list numbers.

def get_largest_list(numbers):

    # write the code here

Testing: The largest in a list#

Check if your function returns the expected value using the cell below.

Tip: The numbers list bellow is defined using a short syntax known as List Comprehension.

import unittest

class UnitTests(unittest.TestCase):
    def test_type(self):
        self.assertEqual(type(get_largest_list([1,2,3,4,5,100])), type(100), 'The function should return an integer.')
    def test_position0(self):
        x = [100,1,2,3,4,5,6,7,8,9]
        self.assertEqual(get_largest_list(x), 100, 'The function should return 100')
    def test_position3(self):
        x = [0,1,2,100,4,5,6,7,8,9]
        self.assertEqual(get_largest_list(x), 100, 'The function should return 100')
    def test_position6(self):
        x = [0,1,2,3,4,5,100,7,8,9]
        self.assertEqual(get_largest_list(x), 100, 'The function should return 100')
    def test_position9(self):
        x = [0,1,2,3,4,5,6,7,8,100]
        self.assertEqual(get_largest_list(x), 100, 'The function should return 100')
        
unittest.main(argv=[''], verbosity=2,exit=False)