Skip to content

Commit fe44be7

Browse files
authored
PR #40: Temperature Converter
Add temperature converter project Merge pull request #40 from omprakash0702/add-temperature-converter
2 parents 7780980 + dc43e64 commit fe44be7

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

Temperature_Converter/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# 🌡️ Temperature Converter
2+
3+
A simple and interactive Python program to convert temperatures between **Celsius**, **Fahrenheit**, and **Kelvin**.
4+
5+
## 🚀 Features
6+
- Convert between all major temperature units
7+
- Clean and easy-to-use CLI interface
8+
- Accurate conversion formulas
9+
10+
## 🧩 How to Run
11+
```bash
12+
python temperature_converter.py
13+
```
14+
15+
## 📖 Example
16+
```
17+
🌡️ Temperature Converter
18+
1. Celsius to Fahrenheit
19+
2. Fahrenheit to Celsius
20+
3. Celsius to Kelvin
21+
4. Kelvin to Celsius
22+
5. Fahrenheit to Kelvin
23+
6. Kelvin to Fahrenheit
24+
Enter choice (1–6): 1
25+
Enter Celsius: 25
26+
25°C = 77.00°F
27+
```
28+
29+
---
30+
31+
**Simple. Accurate. Handy.**
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Temperature Converter
2+
# Converts temperature between Celsius, Fahrenheit, and Kelvin
3+
4+
def celsius_to_fahrenheit(celsius):
5+
return (celsius * 9 / 5) + 32
6+
7+
8+
def fahrenheit_to_celsius(fahrenheit):
9+
return (fahrenheit - 32) * 5 / 9
10+
11+
12+
def celsius_to_kelvin(celsius):
13+
return celsius + 273.15
14+
15+
16+
def kelvin_to_celsius(kelvin):
17+
return kelvin - 273.15
18+
19+
20+
def fahrenheit_to_kelvin(fahrenheit):
21+
return (fahrenheit - 32) * 5 / 9 + 273.15
22+
23+
24+
def kelvin_to_fahrenheit(kelvin):
25+
return (kelvin - 273.15) * 9 / 5 + 32
26+
27+
28+
def main():
29+
print("🌡️ Temperature Converter")
30+
print("1. Celsius to Fahrenheit")
31+
print("2. Fahrenheit to Celsius")
32+
print("3. Celsius to Kelvin")
33+
print("4. Kelvin to Celsius")
34+
print("5. Fahrenheit to Kelvin")
35+
print("6. Kelvin to Fahrenheit")
36+
37+
choice = input("Enter choice (1–6): ")
38+
39+
if choice == "1":
40+
c = float(input("Enter Celsius: "))
41+
print(f"{c}°C = {celsius_to_fahrenheit(c):.2f}°F")
42+
elif choice == "2":
43+
f = float(input("Enter Fahrenheit: "))
44+
print(f"{f}°F = {fahrenheit_to_celsius(f):.2f}°C")
45+
elif choice == "3":
46+
c = float(input("Enter Celsius: "))
47+
print(f"{c}°C = {celsius_to_kelvin(c):.2f}K")
48+
elif choice == "4":
49+
k = float(input("Enter Kelvin: "))
50+
print(f"{k}K = {kelvin_to_celsius(k):.2f}°C")
51+
elif choice == "5":
52+
f = float(input("Enter Fahrenheit: "))
53+
print(f"{f}°F = {fahrenheit_to_kelvin(f):.2f}K")
54+
elif choice == "6":
55+
k = float(input("Enter Kelvin: "))
56+
print(f"{k}K = {kelvin_to_fahrenheit(k):.2f}°F")
57+
else:
58+
print("Invalid choice ❌")
59+
60+
61+
if __name__ == "__main__":
62+
main()

0 commit comments

Comments
 (0)