2. Write a python program to convert the temperature either from celsius to fahrenheit or from fahrenheit to celsius. To request the program user to input the temperature value with their F or C to represent fahrenheit or celsius. One of the example is shown below.
The output is:
Please input the temperature for convertion (e.g:101C, 30F): 40C
Expected Answer:
The temperature in Fahrenheit is 104 degrees.
Sample Answer:
temp_input = input("Please input the temperature for convertion (e.g:101C, 30F): ")
num_input = int(temp_input[:-1])
initial_letter = temp_input[-1]
if initial_letter.upper() == "C":
result = int(round((9 * num_input) / 5 + 32))
final_letter = "Fahrenheit"
elif initial_letter.upper() == "F":
result = int(round((num_input - 32) * 5 / 9))
final_letter = "Celsius"
quit()
print("The temperature in", final_letter , "is", result, "degrees.")
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)