Question

Fahrenheit scale is a temperate scale and it uses the degree Fahrenheit (symbol °F) as the...

Fahrenheit scale is a temperate scale and it uses the degree Fahrenheit (symbol °F) as the unit. Celsius scale is another temperature scale and its symbol is °C. Fahrenheit is used by United States whereas all other countries in the world use Celsius. The formulas of conversion between Fahrenheit and Celsius are as follows:

From Fahrenheit: [°C] = ([°F] − 32) × 5⁄9

From Celsius: [°F] = [°C] × 9⁄5 + 32

Write a function named convertTemp( degree, ForC ) to convert the temperature between F and C. The function takes two parameters, the first parameter is the degree of temperature and the second parameter is a value of either “F” or “C”, telling if the degree is in Fahrenheit or Celsius respectively. The function should return the degree of temperature. For examples:

convertTemp( 50, “F” ) should return 10

convertTemp( 0, “C” ) should return 32


in python
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Python code:

def convertTemp( degree, ForC ):
if ForC == "F": #if degree is in fahrenheit then convert degree to celsius.
C = (degree-32)*(5/9) #converting dgree to celsius.
return int(C) #return celsius value.
else: #if degree is in celsius then convert degree to fahrenheit.
F = degree*(5/9)+32 #converting degree to fahrenheit.
return int(F) #return fahrenheit value.

"""reading the degree and ForC i.e temperature is in scale"""
degree = int(input("Enter degree of temperature: "))
ForC = str(input("Enter value of either \"F\" or \"C\" i.e Degree is in Fahrenheit or Celsius: "))

if ForC == "F": #if degree in Fahrenheit then print the degree in celsius
print("Temperature in Celsius:", convertTemp( degree, ForC ))
else: #if degree in celsius then print the degree in Fahrenheit.
print("Temperature in Fahrenheit:", convertTemp( degree, ForC ))

image of code:

outputs:

Add a comment
Know the answer?
Add Answer to:
Fahrenheit scale is a temperate scale and it uses the degree Fahrenheit (symbol °F) as the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • FOR PYTHON Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice...

    FOR PYTHON Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom functionc_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a...

  • Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The...

    Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom function c_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a value-returning...

  • i need a python code For an exact conversion between "Fahrenheit temperature scale" and "Celsius temperature...

    i need a python code For an exact conversion between "Fahrenheit temperature scale" and "Celsius temperature scale", the following formulas can be applied. Here, F is the value in Fahrenheit and the value in Celsius: Temperature Conversions C = 5 9 (F - 32) F = (š xc) + 3 Write a Python program that uses the above formula to convert Celsius to Fahrenheit and vice versa. We ask user to input "Enter a degree: ", and then we get...

  • in matlab Fahrenheit and Celsius are related by equation: TeT 32)/1.8 Create a function called tempConv...

    in matlab Fahrenheit and Celsius are related by equation: TeT 32)/1.8 Create a function called tempConv that will convert temperature between Fahrenheit and Celsius The function should have two input parameters: one is a single temperature in degrees and the other one is the input temperature scale character 'C'or 'F The function should return the converted temperature as variable temp

  • Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The...

    Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom function c_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a value-returning...

  • 11) The formula C = -32) expresses the relationship between Fahrenheit temperature, F, and Celsius temperature,...

    11) The formula C = -32) expresses the relationship between Fahrenheit temperature, F, and Celsius temperature, C. Use the formula to convert 50°F to it equivalent temperature on the Celsius scale, rounded to the nearest degree A) 28°C B) -4°C C) 32°C D) 10°C I

  • Use Python to create a function that collects temperature in degree Celsius as input from a...

    Use Python to create a function that collects temperature in degree Celsius as input from a user and converts it to degree Fahrenheit. The same function should convert temperature from degree Fahrenheit to degree Celsius if the temperature provided was in degree Fahrenheit. You can use branching (for example, if-else) statements within the body of your function ( Hint: First collect the number, then also collect the unit of temperature so you can use that unit of temperature as a...

  • Exercise 5.4 The following program is supposed to convert a temperature in degree Fahrenheit to degree...

    Exercise 5.4 The following program is supposed to convert a temperature in degree Fahrenheit to degree Celsius, but it will not produce the correct result. Use type casting to fix the problem and run the program for the test values. Call your new program ex54.cpp. Test cases: 32 F is 0 C 212 F is 100 C PROGRAM: #include using namespace std; int main( ) {       int t_in_fah, t_in_cel;  //Notice that we declared these two as integers, not the best...

  • C++ Code needed    Celsius Temperature Table The formula for converting a temperature from Fahrenheit to...

    C++ Code needed    Celsius Temperature Table The formula for converting a temperature from Fahrenheit to Celsius is C =5/9(F -32) where F is the Fahrenheit temperature and C is the Celsius temperature. Write a function named celsius that accepts a Fahrenheit temperature as an argument. The function should return the temperature, converted to Celsius. Demonstrate the function by calling it in a loop that displays a table of the Fahrenheit temperatures 0 through 20 and their Celsius equivalents.

  • Write a Python application that allows the user to convert between temperatures in Fahrenheit and temperatures...

    Write a Python application that allows the user to convert between temperatures in Fahrenheit and temperatures in Celsius. Below are the formulas for both, where Tc is temperature in Celsius and Tf is temperature in Fahrenheit: There should be 3 separate py files/classes- the Model, the View, and the Controllers. The Model contains the F/C conversion. The View is the frame. The controller runs the program and communicates between the Controller and Model

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT