Unit Converter

 def convert_temperature(value, from_unit, to_unit):

    if from_unit == "Celsius" and to_unit == "Fahrenheit":

        return (value * 9/5) + 32

    elif from_unit == "Fahrenheit" and to_unit == "Celsius":

        return (value - 32) * 5/9

    elif from_unit == "Celsius" and to_unit == "Kelvin":

        return value + 273.15

    elif from_unit == "Kelvin" and to_unit == "Celsius":

        return value - 273.15

    elif from_unit == "Fahrenheit" and to_unit == "Kelvin":

        return (value - 32) * 5/9 + 273.15

    elif from_unit == "Kelvin" and to_unit == "Fahrenheit":

        return (value - 273.15) * 9/5 + 32

    return value


def convert_length(value, from_unit, to_unit):

    conversion_factors = {

        "meters": 1,

        "kilometers": 0.001,

        "centimeters": 100,

        "millimeters": 1000,

        "inches": 39.3701,

        "feet": 3.28084,

        "miles": 0.000621371,

    }

    return value * conversion_factors[to_unit] / conversion_factors[from_unit]


def convert_weight(value, from_unit, to_unit):

    conversion_factors = {

        "kilograms": 1,

        "grams": 1000,

        "milligrams": 1_000_000,

        "pounds": 2.20462,

        "ounces": 35.274,

    }

    return value * conversion_factors[to_unit] / conversion_factors[from_unit]


def main():

    print("Unit Converter")

    print("1. Temperature")

    print("2. Length")

    print("3. Weight")

    choice = input("Choose a category (1/2/3): ")


    if choice == "1":

        print("\nTemperature Units: Celsius, Fahrenheit, Kelvin")

        value = float(input("Enter the value to convert: "))

        from_unit = input("Convert from: ").capitalize()

        to_unit = input("Convert to: ").capitalize()

        result = convert_temperature(value, from_unit, to_unit)

        print(f"{value} {from_unit} is equal to {result:.2f} {to_unit}")


    elif choice == "2":

        print("\nLength Units: meters, kilometers, centimeters, millimeters, inches, feet, miles")

        value = float(input("Enter the value to convert: "))

        from_unit = input("Convert from: ").lower()

        to_unit = input("Convert to: ").lower()

        result = convert_length(value, from_unit, to_unit)

        print(f"{value} {from_unit} is equal to {result:.2f} {to_unit}")


    elif choice == "3":

        print("\nWeight Units: kilograms, grams, milligrams, pounds, ounces")

        value = float(input("Enter the value to convert: "))

        from_unit = input("Convert from: ").lower()

        to_unit = input("Convert to: ").lower()

        result = convert_weight(value, from_unit, to_unit)

        print(f"{value} {from_unit} is equal to {result:.2f} {to_unit}")


    else:

        print("Invalid choice! Please select 1, 2, or 3.")


if __name__ == "__main__":

    main()


Managing Students

import os

import platform

global listStd 

listStd = ["Amal", "Appu", "Malavika", "Seetha"]

def manageStudent(): 

global bye

bye = "bye!!"

print(""" 

Welcome To Student Management System


Enter 1 : To View Student's List 

Enter 2 : To Add New Student 

Enter 3 : To Search Student 

Enter 4 : To Remove Student 

""")

try: 

userInput = int(input("Please Select An Above Option: "))

except ValueError:

exit("\nThat's Not A Number")

else:

print("\n") 

if(userInput == 1): 

print("List Students\n")  

for students in listStd:

print("=> {}".format(students))

elif(userInput == 2): 

newStd = input("Enter New Student: ")

if(newStd in listStd): 

print("\nThis Student {} Already In The Database".format(newStd))  

else:

listStd.append(newStd)

print("\n=> New Student {} Successfully Add \n".format(newStd))

for students in listStd:

print("=> {}".format(students))

elif(userInput == 3): 

srcStd = input("Enter Student Name To Search: ")

if(srcStd in listStd): 

print("\n=> Record Found Of Student {}".format(srcStd))

else:

print("\n=> No Record Found Of Student {}".format(srcStd)) 

elif(userInput == 4): 

rmStd = input("Enter Student Name To Remove: ")

if(rmStd in listStd): 

listStd.remove(rmStd)

print("\n=> Student {} Successfully Deleted \n".format(rmStd))

for students in listStd:

print("=> {}".format(students))

else:

print("\n=> No Record Found of This Student {}".format(rmStd)) 

 

elif(userInput < 1 or userInput > 4):

print("Please Enter Valid Option")

manageStudent()

def runAgain():

runAgn = input("\nwant To Run Again Y/n: ")

if(runAgn.lower() == 'y'):

if(platform.system() == "Windows"): 

print(os.system('cls')) 

else:

print(os.system('clear'))

manageStudent()

runAgain()

else:

quit(bye) 

runAgain()


Contact Storing

names = []

phone_numbers = []

num = 3

for i in range(num):

    name = input("Name: ")

    phone_number = input("Phone Number: ")

    names.append(name)

    phone_numbers.append(phone_number)

print("\nName\t\t\tPhone Number\n")

for i in range(num):

    print("{}\t\t\t{}".format(names[i], phone_numbers[i]))

search_term = input("\nEnter search term: ")

print("Search result:")

if search_term in names:

    index = names.index(search_term)

    phone_number = phone_numbers[index]

    print("Name: {}, Phone Number: {}".format(search_term, phone_number))

else:

    print("Name Not Found")

Tic Tac Toe Board

import turtle 

ws=turtle.Screen()

t=turtle.Turtle()

t.color("Blue")

t.width("2")

t.speed(2)

for i in range(4):

t.forward(300)

t.left(90)

t.penup()

t.goto(0,100)

t.pendown()

t.forward(300)

t.penup()

t.goto(0,200)

t.pendown()

t.forward(300)

t.penup()

t.goto(100,0)

t.pendown()

t.left(90)

t.forward(300)

t.penup()

t.goto(200,0)

t.pendown()

t.forward(300)

Sorting Hotel info Using Given Data

class Hotel :

sortParam='name'

def __init__(self) -> None:

self.name=''

self.roomAvl=0

self.location=''

self.rating=int

self.pricePr=0

def __lt__(self,other):

getattr(self,Hotel.sortParam)<getattr(other,Hotel.sortParam)

@classmethod

def sortByName(cls):

cls.sortParam='name'

@classmethod

def sortByRate(cls):

cls.sortParam='rating'

@classmethod

def sortByRoomAvailable(cls) :

cls.sortParam='roomAvl'

def __repr__(self) -> str:

return "PRHOTELS DATA:\nHotelName:{}\tRoom Available:{}\tLocation:{}\tRating:{}\tPricePer Room:{}".format(self.name,self.roomAvl,self.location,self.rating,self.pricePr)

class User:

def __init__(self) -> None:

self.uname=''

self.uId=0

self.cost=0

def __repr__(self) -> str:

return "UserName:{}\tUserId:{}\tBooking Cost:{}".format(self.uname,self.uId,self.cost)

def PrintHotelData(hotels):

for h in hotels:

print(h)

def SortHotelByName(hotels):

print("SORT BY NAME:")

Hotel.sortByName()

hotels.sort()

PrintHotelData(hotels)

print()

def SortHotelByRating(hotels):

print("SORT BY A RATING:")

Hotel.sortByRate()

hotels.sort()

PrintHotelData(hotels)

print()

def PrintHotelBycity(s,hotels):

print("HOTELS FOR {} LOCATION ARE:".format(s))

hotelsByLoc=[h for h in hotels if h.location==s]

PrintHotelData(hotelsByLoc)

print()

def SortByRoomAvailable(hotels):

print("SORT BY ROOM AVAILABLE:")

Hotel.sortByRoomAvailable()

hotels.sort()

PrintHotelData(hotels)

print()

def PrintUserData(userName, userId, bookingCost, hotels):

users=[]

for i in range(3) :

u=User()

u.uname = userName[i]

u.uId = userId[i]

u.cost = bookingCost[i]

users.append(u)

for i in range(len(users)) :

print(users[i],"\tHotel name:",hotels[i].name)

def HotelManagement(userName,

userId,

hotelName,

bookingCost,

rooms,

locations,

ratings,

prices):

hotels=[]

for i in range(3) :

h=Hotel()

h.name = hotelName[i]

h.roomAvl = rooms[i]

h.location = locations[i]

h.rating = ratings[i]

h.pricePr = prices[i]

hotels.append(h)

print()

PrintHotelData(hotels)

SortHotelByName(hotels)

SortHotelByRating(hotels)

PrintHotelBycity("Bangalore",

hotels)

SortByRoomAvailable(hotels)

PrintUserData(userName,

userId,

bookingCost,

hotels)

if __name__ == '__main__':

userName = ["U1", "U2", "U3"]

userId = [2, 3, 4] 

hotelName = ["H1", "H2", "H3"] 

bookingCost = [1000, 1200, 1100]

rooms = [4, 5, 6] 

locations = ["Bangalore",

"Bangalore",

"Mumbai"]

ratings = [5, 5, 3]

prices = [100, 200, 100] 

HotelManagement(userName, userId,

hotelName, bookingCost,

rooms, locations,

ratings, prices)