Question

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 function defined to take a Fahrenheit temperature as a parameter. This function should calculate the equivalent Celsius temperature and return it. In the main function, your program should:

prompt the user to enter a temperature (as a float type) and indicate the temperature scale of the temperature just entered and call the appropriate function from the temps module also if the Celsius temperature is being determined, it should be displayed accurate to three decimal places

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

temps.py

def c_to_f(celsius):
    """
    :param celsius:
    :return: None
    """
    print('{:.3f}'.format(
        (celsius * (9 / 5)) + 32
    ))


def f_to_c(fahrenheit):
    """
    :param fahrenheit:
    :return: float
    """
    return (fahrenheit - 32) * (5 / 9)

temps_main.py

from temps import c_to_f, f_to_c


def main():
    temp = float(input('Enter the temperature : '))
    c_or_f = input('Enter the unit  `C` for celsius and `F` for fahrenheit : ').lower()[0]
    if c_or_f == 'c':
        print("Temp in celsius : {}".format(temp))
        print("Temp in fahrenheit : ", end='')
        c_to_f(temp)
    elif c_or_f == 'f':
        print("Temp in fahrenheit : {}".format(temp))
        print("Temp in celsius : {:.3f}".format(f_to_c(temp)))
    else:
        print('invalid format!!')


if __name__ == '__main__':
    main()

#OUT

Run1
Enter the temperature : 34
Enter the unit  `C` for celsius and `F` for fahrenheit : c
Temp in celsius : 34.0
Temp in fahrenheit : 93.200

Run2
Enter the temperature : 93.2
Enter the unit  `C` for celsius and `F` for fahrenheit : f
Temp in fahrenheit : 93.2
Temp in celsius : 34.000

Please do comment if u have any concern...

Add a comment
Know the answer?
Add Answer to:
Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. 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
  • 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...

  • 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...

  • 8.) Write a C++ program to convert temperature in degrees Fahrenheit to degrees Celsius. This is...

    8.) Write a C++ program to convert temperature in degrees Fahrenheit to degrees Celsius. This is the equation for this conversion: Celsius = 5.0/9.0 (Fahrenheit-32.0) Have your program convert and display the Celsius temperature corresponding to 98.6 degrees Fahrenheit. Your program should produce the following display (replacing the underlines with the correct values): For a Fahrenheit temperature of-_ degrees, the equivalent Celsius temperature is degrees

  • 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...

  • General overview This program will convert a set of temperatures from Fahrenheit to Celsius and Kelvin....

    General overview This program will convert a set of temperatures from Fahrenheit to Celsius and Kelvin. Your program will be reading in three double values. The first values are starting and ending temperatures. The third value is the increment value. There is no prompt for the input. There is an error message that can be displayed. This is discussed later. You need to display output for all of the values between the starting and ending values. First two values are...

  • Write a program in C that will convert all 12 months' average temperature from Celsius to...

    Write a program in C that will convert all 12 months' average temperature from Celsius to Fahrenheit. You need to create an array named aye jump and prompt the user to input average temperature in Celsius for all 12 months. After that, you need to develop a user temperatures from Celsius to Fahrenheit and pass the array as reference and convert all temperatures from Celsius to Fahrenheit. Next, compute the average temperature of the year and assign it to a...

  • Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin...

    Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin Newton Your program should take a character which represents the temperature to convert from and a value to be converted to using the following specification: C - Celsius K - Kelvin N - Newton In addition your program should take in the following character to exit the program: X - eXit the program The numeric input for your program should be of type double....

  • # convert.py # A program to convert Celsius temps to Fahrenheit # by: Susan Computewell def...

    # convert.py # A program to convert Celsius temps to Fahrenheit # by: Susan Computewell def main(): celsius = eval(input("What is the Celsius temperature? ")) fahrenheit = 9/5 * celsius + 32 print("The temperature is", fahrenheit, "degrees Fahrenheit.") main() PORTION ONE: Based the convert.py, so it can convert temperatures from Fahrenheit to Celsius, instead of original Celsius to Fahrenheit. Make sure to change the message to reflect the change of introduction and final result. Name it as: convert_v2.py. Run it...

  • 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...

  • In Python, write a program that converts Celsius temperatures to Fahrenheit temperatures. The formula is as...

    In Python, write a program that converts Celsius temperatures to Fahrenheit temperatures. The formula is as follows: F=(9/5)C+32 The program should ask the user to enter a temperature in Celsius, then display the temperature converted to Fahrenheit.

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