Practical 6: Program to Convert Degree Fahrenheit into Degree Celsius
Problem Statement:
Write a Python program that converts a temperature from Fahrenheit to Celsius. The formula to convert Fahrenheit to Celsius is:
C=(F-32)*5/9
Where:
- CC is the temperature in Celsius
- FF is the temperature in Fahrenheit
Solution Code:
# Program to convert Fahrenheit to Celsius
# Input temperature in Fahrenheit from the user
fahrenheit = float(input("Enter temperature in Fahrenheit: "))
# Convert Fahrenheit to Celsius using the formula
celsius = (fahrenheit - 32) * 5 / 9
# Display the result
print(f"{fahrenheit} Fahrenheit is equal to {celsius} Celsius.")
Output:
- The program will prompt the user to input a temperature in Fahrenheit.
- The program will then convert it into Celsius and display the result.
Enter temperature in Fahrenheit: 80
80.0 Fahrenheit is equal to 26.666666666666668 Celsius.
Process finished with exit code 0
Explanation:
Below is the explanation of F.E. PPS Unit 1 Practical 6 solution where we have written Program to Convert Degree Fahrenheit into Degree Celsius
- Input of Fahrenheit Value:
- The program starts by asking the user to input a temperature in Fahrenheit using the input() function. This input is then converted into a float type to accommodate decimal values.
- Conversion Formula:
- The program uses the formula C=(F−32)×59C = \frac{(F – 32) \times 5}{9} to convert the inputted Fahrenheit value to Celsius.
- The subtraction (fahrenheit – 32) is performed first, followed by multiplication by 5, and then division by 9.
- Displaying the Result:
- Finally, the program prints the converted Celsius temperature using the print() function, displaying the result in a clear format.
Key Concept Learned:
- Mathematical Operations:
- The program demonstrates how to apply basic arithmetic operations to solve a real-world problem, using subtraction, multiplication, and division.
- Input and Type Conversion:
- The program shows how to use the input() function to accept user input and convert it to a float type for mathematical calculations.
- Working with Formulas:
- The practical demonstrates how to implement a simple mathematical formula in a Python program to achieve a desired conversion or result. In this case, converting Fahrenheit to Celsius.
- String Formatting:
- The program uses Python’s f-string formatting to neatly display the results, which is a convenient way to embed expressions inside string literals.