Skip to content

Commit e53ebec

Browse files
Create temperature_converter.py
1 parent 10a0de1 commit e53ebec

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

Python/temperature_converter.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""
2+
🌡️ Temperature Converter CLI Tool
3+
---------------------------------
4+
A simple Python script to convert temperatures between
5+
Celsius, Fahrenheit, and Kelvin.
6+
7+
🎯 Author: Aditya Rana
8+
🗓️ For: Hacktoberfest 2025
9+
"""
10+
11+
def celsius_to_fahrenheit(c):
12+
"""Convert Celsius to Fahrenheit."""
13+
return (c * 9/5) + 32
14+
15+
def fahrenheit_to_celsius(f):
16+
"""Convert Fahrenheit to Celsius."""
17+
return (f - 32) * 5/9
18+
19+
def celsius_to_kelvin(c):
20+
"""Convert Celsius to Kelvin."""
21+
return c + 273.15
22+
23+
def kelvin_to_celsius(k):
24+
"""Convert Kelvin to Celsius."""
25+
return k - 273.15
26+
27+
28+
def main():
29+
print("🌡️ Temperature Converter")
30+
print("---------------------------")
31+
print("1. Celsius → Fahrenheit")
32+
print("2. Fahrenheit → Celsius")
33+
print("3. Celsius → Kelvin")
34+
print("4. Kelvin → Celsius")
35+
36+
choice = input("Choose an option (1–4): ")
37+
38+
try:
39+
temp = float(input("Enter temperature value: "))
40+
except ValueError:
41+
print("❌ Invalid input! Please enter a numeric value.")
42+
return
43+
44+
if choice == "1":
45+
print(f"{temp}°C = {celsius_to_fahrenheit(temp):.2f}°F")
46+
elif choice == "2":
47+
print(f"{temp}°F = {fahrenheit_to_celsius(temp):.2f}°C")
48+
elif choice == "3":
49+
print(f"{temp}°C = {celsius_to_kelvin(temp):.2f}K")
50+
elif choice == "4":
51+
print(f"{temp}K = {kelvin_to_celsius(temp):.2f}°C")
52+
else:
53+
print("❌ Invalid option selected!")
54+
55+
56+
if __name__ == "__main__":
57+
main()

0 commit comments

Comments
 (0)