├── alarm.py ├── atm.py ├── brightness.py ├── cal.py ├── clock.py ├── cmpres.py ├── currency_conv.py ├── dice.py ├── guess_no.py ├── jdbc.py ├── lang_detect.py ├── laptop_battery.py ├── monitor.py ├── notification.py ├── pychatgtp.py ├── python_pdf_extraction.py ├── rock_paper.py ├── similarity.py ├── spell_check.py ├── text_senti.py ├── todo.py ├── webscrapping.py ├── word_freq.py └── wordcount.py /alarm.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | print(time.strftime("%H:%M")) 4 | alarm_time = input("Enter the alarm time (HH:MM): ") 5 | while time.strftime("%H:%M") != alarm_time: 6 | time.sleep(1) 7 | print("Time to wake up!") -------------------------------------------------------------------------------- /atm.py: -------------------------------------------------------------------------------- 1 | class ATM: 2 | def __init__(self, balance=1000): 3 | self.balance = balance 4 | 5 | def check_balance(self): 6 | return f"Your account balance is ${self.balance}" 7 | 8 | def deposit(self, amount): 9 | self.balance += amount 10 | return f"Deposited ${amount}. Your new balance is ${self.balance}" 11 | 12 | def withdraw(self, amount): 13 | if self.balance >= amount: 14 | self.balance -= amount 15 | return f"Withdrew ${amount}. Your new balance is ${self.balance}" 16 | else: 17 | return "Insufficient funds. Withdrawal failed." 18 | 19 | # Create an instance of the ATM 20 | atm = ATM() 21 | while True: 22 | print("1. Check Balance") 23 | print("2. Deposit") 24 | print("3. Withdraw") 25 | print("4. Exit") 26 | 27 | choice = input("Enter your choice: ") 28 | 29 | if choice == '1': 30 | print(atm.check_balance()) 31 | elif choice == '2': 32 | amount = float(input("Enter the deposit amount: ")) 33 | print(atm.deposit(amount)) 34 | elif choice == '3': 35 | amount = float(input("Enter the withdrawal amount: ")) 36 | print(atm.withdraw(amount)) 37 | elif choice == '4': 38 | print("Thank you for using the ATM. Goodbye!") 39 | break 40 | else: 41 | print("Invalid choice. Please select a valid option.") 42 | -------------------------------------------------------------------------------- /brightness.py: -------------------------------------------------------------------------------- 1 | # importing the module 2 | import screen_brightness_control as sbc 3 | 4 | # get current brightness value 5 | print(sbc.get_brightness()) 6 | 7 | 8 | #set the brightness of the primary display to 75% 9 | sbc.set_brightness(100, display=0) 10 | 11 | -------------------------------------------------------------------------------- /cal.py: -------------------------------------------------------------------------------- 1 | while True: 2 | print("Options:") 3 | print("Enter 'add' for addition") 4 | print("Enter 'sub' for subtraction") 5 | print("Enter 'mul' for multiplication") 6 | print("Enter 'div' for division") 7 | print("Enter 'quit' to end the program") 8 | 9 | user_input = input(": ") 10 | 11 | if user_input == "quit": 12 | break 13 | elif user_input in ("add", "sub", "mul", "div"): 14 | num1 = float(input("Enter first number: ")) 15 | num2 = float(input("Enter second number: ")) 16 | 17 | if user_input == "add": 18 | print(f"Result: {num1 + num2}") 19 | elif user_input == "sub": 20 | print(f"Result: {num1 - num2}") 21 | elif user_input == "mul": 22 | print(f"Result: {num1 * num2}") 23 | elif user_input == "div": 24 | if num2 != 0: 25 | print(f"Result: {num1 / num2}") 26 | else: 27 | print("Cannot divide by zero.") 28 | else: 29 | print("Invalid input") 30 | else: 31 | print("Invalid input") -------------------------------------------------------------------------------- /clock.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from time import strftime 3 | 4 | root = tk.Tk() 5 | root.title("Clock") 6 | 7 | def time(): 8 | string = strftime('%H:%M:%S %p') 9 | label.config(text=string) 10 | label.after(1000, time) 11 | 12 | label = tk.Label(root, font=("calibri", 40, "bold"), background="white", foreground="black") 13 | label.pack(anchor='center') 14 | 15 | time() 16 | root.mainloop() -------------------------------------------------------------------------------- /cmpres.py: -------------------------------------------------------------------------------- 1 | import gzip 2 | 3 | input_file = "input.txt" 4 | output_file = "compressed.gz" 5 | 6 | with open(input_file, "rb") as f_in, gzip.open(output_file, "wb") as f_out: 7 | f_out.writelines(f_in) 8 | 9 | print(f"File '{input_file}' has been compressed to '{output_file}'.") 10 | -------------------------------------------------------------------------------- /currency_conv.py: -------------------------------------------------------------------------------- 1 | from currency_converter import CurrencyConverter 2 | 3 | # Create an instance of the CurrencyRates class 4 | c = CurrencyConverter() 5 | 6 | # Input the amount and currencies 7 | amount = input("Enter the amount: ") 8 | from_currency = input("From Currency ").upper() 9 | to_currency = input("To Currency ").upper() 10 | 11 | # Convert the currency 12 | result = c.convert(amount,from_currency, to_currency) 13 | 14 | # Display the result 15 | print(result) -------------------------------------------------------------------------------- /dice.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | while True: 4 | input("Press Enter to roll the die...") 5 | result = random.randint(1, 6) 6 | print(f"The die shows: {result}") 7 | again = input("Roll again? (y/n): ") 8 | if again.lower() != 'y': 9 | break -------------------------------------------------------------------------------- /guess_no.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | random_number = random.randint(1, 100) 4 | attempts = 0 5 | 6 | while True: 7 | guess = int(input("Guess the number: ")) 8 | attempts += 1 9 | 10 | if guess == random_number: 11 | print(f"Congratulations! You guessed it in {attempts} attempts.") 12 | break 13 | elif guess < random_number: 14 | print("Try higher.") 15 | else: 16 | print("Try lower.") -------------------------------------------------------------------------------- /jdbc.py: -------------------------------------------------------------------------------- 1 | import mysql.connector 2 | 3 | # Replace these variables with your MySQL database credentials 4 | host = 'localhost' 5 | user = 'root' 6 | password = 'root' 7 | database = 'test' 8 | 9 | # Establish a connection to the MySQL server 10 | try: 11 | connection = mysql.connector.connect( 12 | host=host, 13 | user=user, 14 | password=password, 15 | database=database 16 | ) 17 | if connection.is_connected(): 18 | print("Connected to MySQL database") 19 | 20 | # Create a cursor object to interact with the database 21 | cursor = connection.cursor() 22 | 23 | # Execute a SELECT query 24 | cursor.execute("SELECT * FROM employee") 25 | 26 | # Fetch and print the result 27 | records = cursor.fetchall() 28 | for record in records: 29 | print(record) 30 | 31 | # Close the cursor and connection 32 | cursor.close() 33 | connection.close() 34 | 35 | except mysql.connector.Error as e: 36 | print(f"Error: {e}") 37 | -------------------------------------------------------------------------------- /lang_detect.py: -------------------------------------------------------------------------------- 1 | from langdetect import detect 2 | 3 | text = "தமிழ்" #தமிழ் 4 | language = detect(text) 5 | print("Detected language:", language) -------------------------------------------------------------------------------- /laptop_battery.py: -------------------------------------------------------------------------------- 1 | import psutil 2 | 3 | battery = psutil.sensors_battery() 4 | 5 | print("Battery percentage : ", battery.percent) 6 | print("Power plugged in : ", battery.power_plugged) -------------------------------------------------------------------------------- /monitor.py: -------------------------------------------------------------------------------- 1 | import psutil 2 | 3 | # Get a list of all running processes 4 | running_processes = psutil.process_iter(attrs=['pid', 'name', 'status']) 5 | 6 | # Iterate through the list and print process information 7 | for process in running_processes: 8 | process_info = process.info 9 | pid = process_info['pid'] 10 | name = process_info['name'] 11 | status = process_info['status'] 12 | print(f"PID: {pid}, Name: {name}, Status: {status}") 13 | 14 | -------------------------------------------------------------------------------- /notification.py: -------------------------------------------------------------------------------- 1 | from plyer import notification 2 | 3 | title = "Notification Title" 4 | message = "This is a sample notification." 5 | 6 | notification.notify( 7 | title=title, 8 | message=message, 9 | app_name="Python Notification App", 10 | timeout=10 # Notification will disappear after 10 seconds 11 | ) 12 | -------------------------------------------------------------------------------- /pychatgtp.py: -------------------------------------------------------------------------------- 1 | import openai 2 | openai.api_key = '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' 3 | messages = [ {"role": "system", "content": 4 | "You are a philosopher ."} ] 5 | while True: 6 | message = input("User : ") 7 | if message: 8 | messages.append( 9 | {"role": "user", "content": message}, 10 | ) 11 | chat = openai.ChatCompletion.create( 12 | model="gpt-3.5-turbo", messages=messages 13 | ) 14 | reply = chat.choices[0].message.content 15 | print(f"ChatGPT: {reply}") 16 | messages.append({"role": "assistant", "content": reply}) 17 | -------------------------------------------------------------------------------- /python_pdf_extraction.py: -------------------------------------------------------------------------------- 1 | import PyPDF2 2 | 3 | pdfFileObj = open('C://Users//sbgowtham//Desktop//file.pdf', 'rb') 4 | 5 | pdfReader = PyPDF2.PdfFileReader(pdfFileObj) 6 | 7 | print(pdfReader.numPages) 8 | 9 | pageObj = pdfReader.getPage(0) 10 | 11 | print(pageObj.extractText()) 12 | 13 | pdfFileObj.close() 14 | -------------------------------------------------------------------------------- /rock_paper.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | choices = ['rock', 'paper', 'scissors'] 4 | computer_choice = random.choice(choices) 5 | player_choice = input("Choose: rock, paper, or scissors: ").lower() 6 | 7 | if player_choice in choices: 8 | if player_choice == computer_choice: 9 | print("It's a tie!") 10 | elif ( 11 | (player_choice == 'rock' and computer_choice == 'scissors') or 12 | (player_choice == 'paper' and computer_choice == 'rock') or 13 | (player_choice == 'scissors' and computer_choice == 'paper') 14 | ): 15 | print("You win!") 16 | else: 17 | print("Computer wins!") 18 | else: 19 | print("Invalid choice.") -------------------------------------------------------------------------------- /similarity.py: -------------------------------------------------------------------------------- 1 | from fuzzywuzzy import fuzz 2 | 3 | text1 = "This is a sample text for similarity calculation." 4 | text2 = "Here is another text for similarity testing." 5 | 6 | similarity_ratio = fuzz.ratio(text1, text2) 7 | print(f"Similarity Ratio: {similarity_ratio}") 8 | -------------------------------------------------------------------------------- /spell_check.py: -------------------------------------------------------------------------------- 1 | from textblob import Word 2 | 3 | text = "Yourr text with misspelled wrds goes here." 4 | corrected_text = " ".join(Word(word).correct() for word in text.split()) 5 | print(corrected_text) -------------------------------------------------------------------------------- /text_senti.py: -------------------------------------------------------------------------------- 1 | from textblob import TextBlob 2 | 3 | text = "you are a bad person" 4 | analysis = TextBlob(text) 5 | sentiment = analysis.sentiment.polarity 6 | 7 | if sentiment > 0: 8 | print("Positive sentiment") 9 | elif sentiment < 0: 10 | print("Negative sentiment") 11 | else: 12 | print( "Neutral sentiment") -------------------------------------------------------------------------------- /todo.py: -------------------------------------------------------------------------------- 1 | tasks = [] 2 | 3 | while True: 4 | print("1. Add task") 5 | print("2. Remove task") 6 | print("3. List tasks") 7 | print("4. Quit") 8 | 9 | choice = int(input("Enter your choice: ")) 10 | 11 | if choice == 1: 12 | task = input("Enter task: ") 13 | tasks.append(task) 14 | elif choice == 2: 15 | task = input("Enter task to remove: ") 16 | if task in tasks: 17 | tasks.remove(task) 18 | else: 19 | print("Task not found.") 20 | elif choice == 3: 21 | for i, task in enumerate(tasks): 22 | print(f"{i+1}. {task}") 23 | elif choice == 4: 24 | break 25 | else: 26 | print("Invalid choice. Try again.") -------------------------------------------------------------------------------- /webscrapping.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from bs4 import BeautifulSoup 3 | 4 | # Making a GET request 5 | r = requests.get('https://codewithgowtham.blogspot.com/2021/03/sqoop-commands.html') 6 | 7 | # Parsing the HTML 8 | soup = BeautifulSoup(r.content, 'html.parser') 9 | 10 | # find all the anchor tags with "href" 11 | for link in soup.find_all('a'): 12 | print(link.get('href')) -------------------------------------------------------------------------------- /word_freq.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | text = "Your input text goes here Replace this with Your text" 4 | word_counts = Counter(text.split()) 5 | print(word_counts) -------------------------------------------------------------------------------- /wordcount.py: -------------------------------------------------------------------------------- 1 | text = input("Enter a text: ") 2 | word_count = len(text.split()) 3 | print(f"Word count: {word_count}") --------------------------------------------------------------------------------