Fahrenheit to celsius conversion python
Get via App Store Read this post in our app!
Write a function in python for temperature conversion named ‘convert_temp’
Write a function for temperature conversion named ‘convert_temp’.
The function signature should be:
Then write a short program to use the function you wrote (both the function and program should be part of the same file). Your program should prompt the user to enter a temperature scale (assume the user will choose to type ‘F’ or ‘C’) and then prompt the user to enter a number of degrees. Using the values supplied by the user, the program should then call the ‘convert_temp’ function and pass in the two arguments, along these lines:
and the subroutine should produce a line of output that looks like this (for Fahrenheit to Celsius):
or, for a Celsius to Fahrenheit conversion:
The first temperature and scale that you should report are those that the user entered, followed by the converted temperature and other scale.
I have the following code so far:
What need help with, is to add the converted scale (F or C) to my print output.
You need to indent after the : .
The easiest thing you can do is to have the function return the scale of the converted temperature, since it already bases its behavior on the given scale.
It can simply return a tuple, with the destination scale as its fist element
so now the output shows both the original scale and the converted one:
Note: the function prints out an error message if the scale given is not supported. It should raise and exception instead.
Note2: why not convert the input numbers to float?