Question

In: Computer Science

1. Develop a module named temperatures.py with the following functions. Function toCelsius is passed a Fahrenheit...

1. Develop a module named temperatures.py with the following functions.

  • Function toCelsius is passed a Fahrenheit temperature and returns the Celsius equivalent. 1 degree Fahrenheit = 5/9 * (Fahreheit-32) degrees Celsius.
  • Function toFahrenheit is passed a Celsius temperature and returns the Fahrenheit equivalent. 1 degree Celsius = 1.8*Celsisus + 32 degrees Fahrenheit.
  • Function toKPH is passed a speed in miles per hour and returns the kilometers per hour equivalent. 1 kph = mph * 1.609344
  • Function toMPH is passed a speed in kilometers per hour and returns the miles per hour equivalent. 1 mph = kph * 0.62137119
  • Function windchillF is passed the temperature in Fahrenheit (T) and the wind speed in miles per hour (V) and returns the wind chill in Fahrenheit.

WC = 35.74+ 0.6215T−35.75V0.16 +0.4275TV0.16

  • Function windchillC is passed the temperature in Celsius (T) and the wind speed in kilometers per hour (V) and returns the wind chill in Celsius.

WC = 13.12+ 0.6215T−11.37V0.16 +0.3965TV0.16

2. Develop an application in which the user enters lower and upper bounds on temperature in Fahrenheit and lower and upper bounds on wind speed in miles per hour. Two charts are produced. The first chart lists wind chills in Fahrenheit for all combinations of temperature in Fahrenheit and wind speed in miles per hour. The second chart lists wind chills in Celsius for all combinations of equivalent temperatures in Celsius and wind speeds in kilometers per hour.

Required Code Structures:

  • The main function should be listed in def main ( ) function. The main function gets data from the user and calls the display function twice, once to produce the first chart in Fahrenheit and again to produce the second chart in Celsius.
  • A display function is written which is passed code ("F" for Fahrenheit or "C" for Celsius) along with the low and high bounds for temperature in correct units and low and high bounds for wind speed in correct units. This code uses a nested for loop to display a neat chart with field widths (see sample output for design to match). The temperatures increase by 5 each pass and the wind speeds increase by 2. Hint: Use the int function as necessary to convert float values to int values in the for loops.
  • Add your name and a program description as comments at the top of code.
  • All variables must have meaningful names using convention of lower case and a comment.
  • All constants must have meaningful names using convention of upper case and a comment.
  • All functions must have a comment describing purpose or return value

Solutions

Expert Solution

Make sure to add the temperatures.py in the modules directory

Code for the app:

import temperatures

def display(temp_upper,temp_lower,speed_upper,speed_lower):

    # For listing the data in farenheit and MPH

    for i in range(int(temp_lower),int(temp_upper)):

        for j in range(int(speed_lower),int(speed_upper)):

            print(i,j)          # Prints the value of Temp and Wind speen in farenheit and MPH Respectively

            print(windchillF(i,j))  # Prints the value of Wind Chill

    # For listing the data in celcius and KPH

    for i in range(int(toCelsius(temp_lower)),int(toCelsius(temp_upper))):

        for j in range(int(toKPH(speed_lower)),int(toKPH(speed_upper))):

            print(i,j)          # Prints the value of Temp and Wind speen in celcius and KPH Respectively

            print(windchillc(i,j))  # Prints the value of Wind Chill

def main():

    temp_upper = input("Enter the upper bound for temperature in Fahrenheit:")

    temp_lower = input("Enter the lower bound for temperature in Fahrenheit:")

    speed_upper = input("Enter the upper bound for Wind Speed in MPH:")

    speed_lower = input("Enter the lower bound for Wind Speed in MPH:")

    

    display(temp_upper,temp_lower,speed_upper,speed_lower)

main()

Code for temperature.py module:

def toCelsius(fahrenheit):

    return (5/9) * (fahrenheit - 32)

def toFahrenheit(celsius):

    return (celsius * 1.8) + 32

def toKPH(mph):

    return mph * 1.609344

def toMPH(kph):

    return kph * 0.62137119

def windchillF(T,V):

    return (35.74 + 0.6215*T - 35.75 * V **0.16 + 0.4275 * T * V**0.16)

def windchillC(T,V):

    return (13.12 + 0.6215*T - 11.37 * V **0.16 + 0.3965 * T * V**0.16)


Related Solutions

PYTHON: Complete these functions in the module: f2c, a function to convert Fahrenheit temperatures to Celcius....
PYTHON: Complete these functions in the module: f2c, a function to convert Fahrenheit temperatures to Celcius. c2f, a function to convert Celcius termperatures to Fahrenheit. Write f2c() and c2f() as functions that return a true value or False. In other words, these functions do not print — they return. A "true value", in this case, would be a number that corresponds to a temperature. If the user enters an invalid temperature, the function should return False. Create _main(), a function...
Write a Python module that must satisfy the following- Define a function named rinsert. This function...
Write a Python module that must satisfy the following- Define a function named rinsert. This function will accept two arguments, the first a list of items to be sorted and the second an integer value in the range 0 to the length of the list, minus 1. This function shall insert the element corresponding to the second parameter into the presumably sorted list from position 0 to one less than the second parameter’s index.   Define a function named rinsort. This...
Write the following easy Python functions: 1) Write the function named roundDollars(). The function has one...
Write the following easy Python functions: 1) Write the function named roundDollars(). The function has one input, a String named amountStr which consists of a dollar-formatted amount, such as "$ 1,256.86". The returned value is an int representing the number of rounded "dollars" in the amount, (1257 in the sample shown here). You will need to scrub, format and parse the input, then use arithmetic to determine how many rounded dollars the amount contains. roundDollars("$ 1,256.86") → 1257 roundDollars("$ 0.42")...
Create the function named multiplyByAverage used below. The multiplyByAverage function is passed a float array and...
Create the function named multiplyByAverage used below. The multiplyByAverage function is passed a float array and its size and multiplies each element of the passed array by the array's average. in C++. const size_t SIZE = 4; float floatArray[SIZE] = { 42.5, 74.2, 12.4, 24.3 }; multiplyByAverage(floatArray, SIZE); //floatArray is now: { 1629.9, 2845.6, 475.5, 931.9 }
C Programming question: Develop a program named “sample” that prints the value of two functions: 1....
C Programming question: Develop a program named “sample” that prints the value of two functions: 1. Function f1 takes a single input argument of type int and returns the value of its input argument as float 2. Function f2 takes a single input argument of type char and returns an int. The output of f2 is the result of the sum of the values of the global variables, and the input argument minus the value of char ‘a’ plus the...
IN PYTHON 3 LANGUAGE Define a recursive function named immutify; it is passed any data structure...
IN PYTHON 3 LANGUAGE Define a recursive function named immutify; it is passed any data structure that contains int, str, tuple, list, set, frozenset, and dict values (including nested versions of any of these data structures as an argument). It returns an immutable equivalent data structure (one that could be used for values in a set or keys in a dict). The types int, str, and frozenset are already immutable. Convert a set to a frozenset; convert all the values...
Implement the following function in the PyDev module functions.py and test it from a PyDev module...
Implement the following function in the PyDev module functions.py and test it from a PyDev module named : def statistics(n): """ ------------------------------------------------------- Asks a user to enter n values, then calculates and returns the minimum, maximum, total, and average of those values. Use: minimum, maximum, total, average = statistics(n) ------------------------------------------------------- Parameters: n - number of values to process (int > 0) Returns: minimum - smallest of n values (float) maximum - largest of n values (float) total - total of...
Implement the following function in the PyDev module functions.py and test it from a PyDev module...
Implement the following function in the PyDev module functions.py and test it from a PyDev module named : def gym_cost(cost, friends): """ ------------------------------------------------------- Calculates total cost of a gym membership. A member gets a discount according to the number of friends they sign up. 0 friends: 0% discount 1 friend: 5% discount 2 friends: 10% discount 3 or more friends: 15% discount Use: final_cost = gym_cost(cost, friends) ------------------------------------------------------- Parameters: cost - a gym membership base cost (float > 0) friends...
Implement the following function in the PyDev module functions.py and test it from a PyDev module...
Implement the following function in the PyDev module functions.py and test it from a PyDev module named : def wind_speed(speed): """ ------------------------------------------------------- description Use: category = wind_speed(speed) ------------------------------------------------------- Parameters: speed - wind speed in km/hr (int >= 0) Returns: category - description of wind speed (str) ------------------------------------------------------ """ Wind speeds are categorized as: Wind speed (km/h) Category < 39 Breeze 39 - 61 Strong Wind 62 - 88 Gale Winds 89 - 117 Whole Gale > 117 Hurricane The function...
Implement the following function in the PyDev module functions.py and test it from a PyDev module...
Implement the following function in the PyDev module functions.py and test it from a PyDev module named : def fast_food(): """ ------------------------------------------------------- Food order function. Asks user for their order and if they want a combo, and if necessary, what is the side order for the combo: Prices: Burger: $6.00 Wings: $8.00 Fries combo: add $1.50 Salad combo: add $2.00 Use: price = fast_food() ------------------------------------------------------- Returns: price - the price of one meal (float) ------------------------------------------------------- """ Sample testing: Order B...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT