Percentage

Write and save the following functions into the same file named percentage.py.

  1. Write a function percentage1() that takes two integers, the number of persons in a group, and the number of persons in this group that speak English, and returns the percentage of persons in that group that speak English (float). Examples:

    >>> round(percentage1(100, 42), 2)
    42.0
    >>> round(percentage1(99, 33), 2)
    33.33
    >>> round(percentage1(87, 15), 2)
    17.24
    >>> round(percentage1(44, 22), 2)
    50.0
    
    

    Note

    More tests are provided in the percentage1.txt file.

  2. Write a function percentage2() that takes the initial price of a product and the percentage of VAT (value-added tax) to be applied, and returns the final price of that item. All are type float values. Examples:

    >>> round(percentage2(100.0, 12.0), 2)
    112.0
    >>> round(percentage2(99.99, 6.2), 2)
    106.19
    >>> round(percentage2(87.4, 18.0), 2)
    103.13
    >>> round(percentage2(44.43, 21.5), 2)
    53.98
    
    
  3. Write a function percentage3() that takes two parameters: the price of an oil can at the ‘Supersale’ mall and the price of the same item at the ‘Superscam’ store, and returns the percentage of the price increase of that product at ‘Superscam’ in relation to the price at ‘Supersale’. Use the previous function percentage1(). Examples:

    >>> round(percentage3(8.0, 10.0), 2)
    25.0
    >>> round(percentage3(9.5, 12.2), 2)
    28.42
    >>> round(percentage3(11.5, 15.9), 2)
    38.26
    >>> round(percentage3(4.5, 5.9), 2)
    31.11
    

    Note

    More tests are provided in the percentage3.txt file.

Solution

A solution is provided in the percentage.py file.