Write a Python code to convert Fahrenheit to Celsius
- User
Write a Python code to convert Fahrenheit to Celsius
Assistant
Here's a simple Python function that converts temperature from Fahrenheit to Celsius:
pythondef fahrenheit_to_celsius(fahrenheit): celsius = (fahrenheit - 32) * 5/9 return celsius # Test the function print(fahrenheit_to_celsius(68)) # should print 20.0 print(fahrenheit_to_celsius(32)) # should print 0.0 print(fahrenheit_to_celsius(212)) # should print 100.0In this function, we first subtract 32 from the Fahrenheit value, and then multiply by 5/9 to convert the value to Celsius. The function returns the Celsius value.
In the test examples, we use the function to convert some common Fahrenheit values to Celsius. You can add more examples as needed.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.