Conversions

Save all functions into the same file named conversions.py.

  1. Write the function seconds() that takes a time expressed in hours, minutes and seconds, and returns the same time value expressed in total seconds.

    See the following examples:

    >>> s = seconds(12, 30, 25)
    >>> s
    45025
    
    seconds of 1 hour
    
    >>> s = seconds(1, 0, 0)
    >>> s
    3600
    

    Note

    More tests are provided in the seconds.txt file.

  2. Write a function hms() that takes a time expressed in seconds, and returns the same time value expressed in hours, minutes and seconds.

    See the following examples:

    >>> hms(45025)
    (12, 30, 25)
    
    One hour
    
    >>> hms(3600)
    (1, 0, 0)
    

    Note

    More tests are provided in a function hms.txt file.

  3. Write a function kp_to_newtons() that takes a weight expressed in kiloponds, and returns the same value expressed in Newtons.

    See the following examples:

    >>> f = kp_to_newtons(1.019361)
    >>> round(f,8)
    9.99993141
    
    >>> f = kp_to_newtons(1)
    >>> round(f,2)
    9.81
    

    Note

    More tests are provided in the kp_to_newtons.txt file.

  4. Write a function miles_to_meters() that takes a distance expressed in miles, and returns the same distance expressed in meters.

    See the following examples:

    >>> met = miles_to_meters(1)
    >>> round(met,2)
    1609.34
    
    >>> met = miles_to_meters(12)
    >>> round(met,2)
    19312.13
    

    Note

    More tests are provided in the miles_to_meters.txt file.

  5. Write a function convert() that takes length expressed in meters (integer), and returns the same length expressed in Km, Hm, Dm and m.

    See the following examples:

    >>> convert(1234)
    (1, 2, 3, 4)
    
    >>> convert(45)
    (0, 0, 4, 5)
    
    >>> convert(1000)
    (1, 0, 0, 0)
    
    

    Note

    More tests are provided in the convert.txt file.

  6. Write a function celsius_to_fahrenheit() that takes a temperature expressed in degrees Celsius, and returns the same temperature expressed in degrees Fahrenheit.

    See the following examples:

    >>> round(celsius_to_fahrenheit(-31.2), 2)
    -24.16
    >>> round(celsius_to_fahrenheit(-12.5), 2)
    9.5
    >>> round(celsius_to_fahrenheit(0.0), 2)
    32.0
    >>> round(celsius_to_fahrenheit(34.6), 2)
    94.28
    
    

    Note

    More tests are provided in the celsius_to_fahrenheit.txt file.

  7. Write a function celsius_to_kelvin() that takes a temperature expressed in degrees Celsius, and returns the same temperature expressed in degrees Kelvin.

    See the following examples:

    >>> round(celsius_to_kelvin(-31.2), 2)
    241.95
    >>> round(celsius_to_kelvin(-12.5), 2)
    260.65
    >>> round(celsius_to_kelvin(0.0), 2)
    273.15
    >>> round(celsius_to_kelvin(34.6), 2)
    307.75
    
    

    Note

    More tests are provided in the celsius_to_kelvin.txt file.

  8. Write a function degrees_to_radians() that takes an angle expressed in degrees, and returns the same angle expressed in radians. Look up in the math library for related functions and compare the results.

    See the following examples:

    >>> round(degrees_to_radians(-31.2), 2)
    -0.54
    >>> round(degrees_to_radians(90), 2)
    1.57
    >>> round(degrees_to_radians(-180), 2)
    -3.14
    >>> round(degrees_to_radians(45), 2)
    0.79
    
    

    Note

    More tests are provided in the degrees_to_radians.txt file.

Solutions

A solution of these functions is provided in the conversions.py file.