Skip to content
Open

Moiz #111

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 51 additions & 40 deletions Temperature_Converter/temperature_converter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Temperature Converter
# Converts temperature between Celsius, Fahrenheit, and Kelvin

from tkinter import *
window = Tk()
window.title("temperature_converter")
def celsius_to_fahrenheit(celsius):
return (celsius * 9 / 5) + 32


def fahrenheit_to_celsius(fahrenheit):
return (fahrenheit - 32) * 5 / 9

Expand All @@ -24,39 +23,51 @@ def fahrenheit_to_kelvin(fahrenheit):
def kelvin_to_fahrenheit(kelvin):
return (kelvin - 273.15) * 9 / 5 + 32


def main():
print("🌡️ Temperature Converter")
print("1. Celsius to Fahrenheit")
print("2. Fahrenheit to Celsius")
print("3. Celsius to Kelvin")
print("4. Kelvin to Celsius")
print("5. Fahrenheit to Kelvin")
print("6. Kelvin to Fahrenheit")

choice = input("Enter choice (1–6): ")

if choice == "1":
c = float(input("Enter Celsius: "))
print(f"{c}°C = {celsius_to_fahrenheit(c):.2f}°F")
elif choice == "2":
f = float(input("Enter Fahrenheit: "))
print(f"{f}°F = {fahrenheit_to_celsius(f):.2f}°C")
elif choice == "3":
c = float(input("Enter Celsius: "))
print(f"{c}°C = {celsius_to_kelvin(c):.2f}K")
elif choice == "4":
k = float(input("Enter Kelvin: "))
print(f"{k}K = {kelvin_to_celsius(k):.2f}°C")
elif choice == "5":
f = float(input("Enter Fahrenheit: "))
print(f"{f}°F = {fahrenheit_to_kelvin(f):.2f}K")
elif choice == "6":
k = float(input("Enter Kelvin: "))
print(f"{k}K = {kelvin_to_fahrenheit(k):.2f}°F")
else:
print("Invalid choice ❌")


if __name__ == "__main__":
main()
def ctf():
inp = entry.get()
finp = float(inp)
entry.delete(0, END)
entry.insert(0,celsius_to_fahrenheit(finp))
def ftc():
inp = entry.get()
finp = float(inp)
entry.delete(0, END)
entry.insert(0,fahrenheit_to_celsius(finp))
def ctk():
inp = entry.get()
finp = float(inp)
entry.delete(0, END)
entry.insert(0,celsius_to_kelvin(finp))
def ktc():
inp = entry.get()
finp = float(inp)
entry.delete(0, END)
entry.insert(0,kelvin_to_celsius(finp))
def ftk():
inp = entry.get()
finp = float(inp)
entry.delete(0, END)
entry.insert(0,fahrenheit_to_kelvin(finp))
def ktf():
inp = entry.get()
finp = float(inp)
entry.delete(0, END)
entry.insert(0,kelvin_to_fahrenheit(finp))


entry = Entry(window,bg="gray",fg="black",font="bold")
button1 = Button(window,bg="black",fg="white",font="bold",text="C t F",width=20,command=ctf)
button2 = Button(window,bg="black",fg="white",font="bold",text="F t C",width=20,command=ftc)
button3 = Button(window,bg="black",fg="white",font="bold",text="C t K",width=20,command=ctk)
button4 = Button(window,bg="black",fg="white",font="bold",text="K t C",width=20,command=ktc)
button5 = Button(window,bg="black",fg="white",font="bold",text="F t K",width=20,command=ftk)
button6 = Button(window,bg="black",fg="white",font="bold",text="K t F",width=20,command=ktf)
entry.pack(padx=50,pady=50)
button1.pack(side="left")
button2.pack(side="left")
button3.pack(side="left")
button4.pack(side="left")
button5.pack(side="left")
button6.pack(side="left")

window.mainloop()
Loading