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...
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 }
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...
use eclipse Develop the classes for the following requirements: 1. A class named Employee (general, for...
use eclipse Develop the classes for the following requirements: 1. A class named Employee (general, for college) 2. A class named Instructor (more specific, for college) 3. A class named Staff (more specific, for college, HR officer, Marking staff) Tasks: 1. Figure out the relationships among the classes; 2. Determine the abstract class, and the child classes; 3. For the abstract class, determine at least one abstract method; 4. Each class should at least two data members and one extra...
Requirements: C++ Array/File Functions Write a function named arrayToFile. The function should accept 3 arguments: The...
Requirements: C++ Array/File Functions Write a function named arrayToFile. The function should accept 3 arguments: The name of the file, a pointer to an array, and the size of the array. The function should open the specified file in binary mode, write the contents of the array to file, and then close the file. Write another function named fileToArray. This function should accept 3 arguments: the name of the file, a pointer, to an int array, and the size of...
Write a program that contains 2 functions. Program will call a function named calc_commission that prompt...
Write a program that contains 2 functions. Program will call a function named calc_commission that prompt the user to enter the sales amount and computes and prints with a description the commission paid to salesperson as follows: 10% for sales amount less than $2,000.00, 15% for sales amount less than $10,000.00 and 20% for sales amount less than $20,000.00, then function calc_commission calls another function name assign_base_salary() to ask the user to enter each of 5 salesperson’s base salary ,...
A2_1 Function and modular a) Write a module fun_math.py that contains three functions: cal_factorial(x) – receives...
A2_1 Function and modular a) Write a module fun_math.py that contains three functions: cal_factorial(x) – receives a positive integer “x” and returns the factorial of that number. list_multiples(number, length) – takes a non-negative integer “number” and a positive integer “length”, and returns a list of multiples of “number” up to “length”. For instance (2,3) should return [2,4,6], and (7,5) should return [7,14,21,28,35]. find_max(a_list) – takes a list of integers and returns the largest number. Note that no built-in functions can...
The following is an incomplete function definition of the void function named SomeFun: ________________________________ if (n1...
The following is an incomplete function definition of the void function named SomeFun: ________________________________ if (n1 > 0): index = n2 while index < n3: print(index, end=" ") index += n1 else: print("step should be positive.") The function SomeFun takes 3 numbers as parameters and tries to print numbers between the first and the second parameters with the increment of the third parameter.   For example function call SomeFun(1, 10, 2) generates 1 3 5 7 9 The function call SomeFun(10,...
Develop a routine to convert Celcius to Fahrenheit. Have a form pass the values and a...
Develop a routine to convert Celcius to Fahrenheit. Have a form pass the values and a parm indicating what time of conversion is taking place. Use a function (if possible). Return the correct value. Here is the formula: C = (F - 32) * 5/9 hw8.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title></head> <body> <p>Convert Temp</p> <form id="form1" name="form1" method="get" action="hw8.php"> <table width="300" border="1"> <tr> <td width="122">Enter Temp </td>...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT