Image Resizer with a GUI

 import tkinter as tk

from tkinter import filedialog, messagebox

from PIL import Image, ImageTk


def select_image():

    global img, img_path

    img_path = filedialog.askopenfilename(

        filetypes=[("Image Files", "*.jpg;*.jpeg;*.png;*.bmp;*.gif")]

    )

    if not img_path:

        return

    img = Image.open(img_path)

    preview_image(img)


def preview_image(image):

    # Resize for preview

    preview = image.copy()

    preview.thumbnail((300, 300))

    tk_img = ImageTk.PhotoImage(preview)

    img_label.config(image=tk_img)

    img_label.image = tk_img


def resize_image():

    global img, img_path

    if not img_path:

        messagebox.showerror("Error", "No image selected!")

        return


    try:

        new_width = int(width_entry.get())

        new_height = int(height_entry.get())

        resized_img = img.resize((new_width, new_height))

        

        save_path = filedialog.asksaveasfilename(

            defaultextension=".png",

            filetypes=[("PNG files", "*.png"), ("JPEG files", "*.jpg"), ("All files", "*.*")]

        )

        if save_path:

            resized_img.save(save_path)

            messagebox.showinfo("Success", f"Image saved to {save_path}")

    except ValueError:

        messagebox.showerror("Error", "Please enter valid width and height values!")

    except Exception as e:

        messagebox.showerror("Error", f"An error occurred: {str(e)}")


# GUI Setup

root = tk.Tk()

root.title("Image Resizer")


frame = tk.Frame(root)

frame.pack(pady=10)


# Image Preview

img_label = tk.Label(frame)

img_label.pack()


# Select Image Button

select_btn = tk.Button(root, text="Select Image", command=select_image)

select_btn.pack(pady=5)


# Input Fields for Width and Height

size_frame = tk.Frame(root)

size_frame.pack(pady=5)

tk.Label(size_frame, text="Width: ").grid(row=0, column=0, padx=5)

width_entry = tk.Entry(size_frame, width=10)

width_entry.grid(row=0, column=1, padx=5)

tk.Label(size_frame, text="Height: ").grid(row=0, column=2, padx=5)

height_entry = tk.Entry(size_frame, width=10)

height_entry.grid(row=0, column=3, padx=5)


# Resize Button

resize_btn = tk.Button(root, text="Resize and Save", command=resize_image)

resize_btn.pack(pady=10)


root.mainloop()


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)