diff --git a/Chauhan_Shyam_R/Task_1/calc.py b/Chauhan_Shyam_R/Task_1/calc.py new file mode 100644 index 0000000..6a30547 --- /dev/null +++ b/Chauhan_Shyam_R/Task_1/calc.py @@ -0,0 +1,50 @@ +class Calc: + + # def __init__(self): + # self.num1 = num1 + # self.num2 = num2 + + def addition(self,num1,num2): + return num1 + num2 + + def subtraction(self,num1,num2): + return num1 - num2 + + def multiplication(self,num1,num2): + return num1 * num2 + + def division(self,num1,num2): + if(num2 == 0): + return "can not divide by Zero" + else: + return num1/num2 + +def main(): + choice = 1 + calc = Calc() + while True: + choice = int(input("Please choose from following \n 1. Addition \n 2. Subtraction \n 3. Multiplication \n 4. Division \n 5. Exit \nEnter your choice : ")) + if (choice != 5): + num1 = int(input("Enter first number : ")) + num2 = int(input("Enter Second number : ")) + else: + pass + if(choice == 1): + temp = calc.addition(num1,num2) + print("Addition is : ",temp) + elif(choice == 2): + temp = calc.subtraction(num1,num2) + print("Subtraction is : ",temp) + elif(choice == 3): + temp = calc.multiplication(num1,num2) + print("Multiplication is : ",temp) + elif(choice == 4): + temp = calc.division(num1,num2) + print("Division is : ",temp) + elif(choice == 5): + exit(0) + else: + print("Wrong choice !") + +if __name__ == '__main__': + main() diff --git a/Chauhan_Shyam_R/Task_10/data_analysis.py b/Chauhan_Shyam_R/Task_10/data_analysis.py new file mode 100644 index 0000000..ebf3f70 --- /dev/null +++ b/Chauhan_Shyam_R/Task_10/data_analysis.py @@ -0,0 +1,40 @@ +import seaborn as sns +import matplotlib.pyplot as plt + +# 1. Load the DataSet: +iris_df = sns.load_dataset('iris') + +# 2. Exploratory Data Analysis (EDA): +print("Dataset information:") +print(iris_df.info()) + +print("\nSummary statistics:") +print(iris_df.describe()) + +print("\nFirst few rows of the dataset:") +print(iris_df.head()) + +# 3. Data Cleaning: +print("\nChecking for missing values:") +print(iris_df.isnull().sum()) + +print("\nChecking for duplicate rows:") +print(iris_df.duplicated().sum()) + +# 4. Aggregation: +species_mean = iris_df.groupby('species').mean() + +# 5. Visualizations: +# Pairplot +sns.pairplot(iris_df, hue='species') +plt.suptitle('Pairplot of Iris Dataset', y=1.02) +plt.show() + +# Correlation Heatmap +plt.figure(figsize=(8, 6)) +sns.heatmap(iris_df.corr(), annot=True, cmap='coolwarm') +plt.title('Correlation Matrix') +plt.show() + +# 6. Correlation Calculations: +correlation_matrix = iris_df.corr() diff --git a/Chauhan_Shyam_R/Task_11/regression.py b/Chauhan_Shyam_R/Task_11/regression.py new file mode 100644 index 0000000..c418a0d --- /dev/null +++ b/Chauhan_Shyam_R/Task_11/regression.py @@ -0,0 +1,50 @@ +from sklearn.datasets import load_diabetes +from sklearn.model_selection import train_test_split +from sklearn.linear_model import LinearRegression +import matplotlib.pyplot as plt +import numpy as np + +# Load the dataset +diabetes = load_diabetes() + +# Prepare the data +X = diabetes.data +y = diabetes.target + +# Split the data into training and testing sets +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) + +# Train the model +model = LinearRegression() +model.fit(X_train, y_train) + +# Evaluate the model +train_score = model.score(X_train, y_train) +test_score = model.score(X_test, y_test) +print(f'Training Score: {train_score:.2f}') +print(f'Testing Score: {test_score:.2f}') + +# Plot residuals +train_residuals = y_train - model.predict(X_train) +test_residuals = y_test - model.predict(X_test) + +plt.figure(figsize=(12, 6)) + +plt.subplot(1, 2, 1) +plt.scatter(model.predict(X_train), train_residuals, alpha=0.5, label='Train Residuals') +plt.axhline(y=0, color='r', linestyle='--') +plt.title('Residual Plot (Training)') +plt.xlabel('Predicted Values') +plt.ylabel('Residuals') +plt.legend() + +plt.subplot(1, 2, 2) +plt.scatter(model.predict(X_test), test_residuals, alpha=0.5, label='Test Residuals') +plt.axhline(y=0, color='r', linestyle='--') +plt.title('Residual Plot (Testing)') +plt.xlabel('Predicted Values') +plt.ylabel('Residuals') +plt.legend() + +plt.tight_layout() +plt.show() diff --git a/Chauhan_Shyam_R/Task_12/be_better.png b/Chauhan_Shyam_R/Task_12/be_better.png new file mode 100644 index 0000000..8c74af8 Binary files /dev/null and b/Chauhan_Shyam_R/Task_12/be_better.png differ diff --git a/Chauhan_Shyam_R/Task_12/image_compression.py b/Chauhan_Shyam_R/Task_12/image_compression.py new file mode 100644 index 0000000..11daa08 --- /dev/null +++ b/Chauhan_Shyam_R/Task_12/image_compression.py @@ -0,0 +1,45 @@ +from PIL import Image +import os + +def compress_image(input_path, output_path, quality=60): + try: + input_image = Image.open(input_path) + + if input_image.mode == 'RGBA': + input_image = input_image.convert('RGB') + + # Determine output format based on file extension + output_format = os.path.splitext(output_path)[1][1:].upper() # Get file extension and convert to uppercase + if output_format not in ['JPEG', 'JPG', 'PNG']: + raise ValueError("Unsupported output format. Supported formats: JPEG, JPG, PNG") + + # Save the compressed image + compressed_image = input_image.copy() + compressed_image.save(output_path, format=output_format, quality=quality) + + print(f"Compressed image saved at: {output_path}") + + except FileNotFoundError: + print(f"Error: The file '{input_path}' was not found.") + except Exception as e: + print(f"Error: {e}") + +def main(): + input_path = r'D:\Python-Programming-Internship\Chauhan_Shyam_R\Task_12\be_better.png' # Adjust this path + output_folder = 'compressed_images' + os.makedirs(output_folder, exist_ok=True) + + # Interactive quality adjustment + try: + quality = int(input("Enter compression quality (0 - 95): ")) + if quality < 0 or quality > 95: + raise ValueError("Compression quality must be between 0 and 95.") + except ValueError: + quality = 60 # Default value if invalid input + + # Compress image + output_path = os.path.join(output_folder, 'compressed_image.png') + compress_image(input_path, output_path, quality) + +if __name__ == "__main__": + main() diff --git a/Chauhan_Shyam_R/Task_2/task2_Todo_list.py b/Chauhan_Shyam_R/Task_2/task2_Todo_list.py new file mode 100644 index 0000000..5037e9c --- /dev/null +++ b/Chauhan_Shyam_R/Task_2/task2_Todo_list.py @@ -0,0 +1,66 @@ +#todo class +class ToDo: + #main task list initialization + def __init__(self): + self.tasks = [] + + def new_task(self,task): + ''' + Adds new task to the list + param task: task to be added + ''' + self.tasks.append(task) + print("Task added sucessfully") + print("") + + def del_task(self,task_index): + ''' + Deletes task from the list by index + param task_index: index of task to be deleted + ''' + self.tasks.pop(task_index - 1) + print("Task deleted successfully") + print("") + + + def mrk_task(self,task_index): + ''' + Marks task from the list as completed by index + param task_index: index of task to be marked as completed + ''' + task = self.tasks[task_index - 1] + self.tasks[task_index - 1] = task + ' - completed' + print("Yey ! task completed") + print("") + + #prints tasks + def prt_task(self): + for task in self.tasks: + index = self.tasks.index(task) + 1 + print("{}.{}".format(index,task)) + print(" ") + +#main method +def main(): + todo = ToDo() + choice = 1 + while True: + choice = int(input("Select option \n 1. Add new task \n 2. Delete task \n 3. Mark task as completed \n 4. Print tasks\n 5. Exit \nEnter Number : ")) + if(choice == 1): + task = input("Enter new task : ") + todo.new_task(task) + elif(choice == 2): + task_index = int(input("Enter task index to delete(get it via printing tasks) : ")) + todo.del_task(task_index) + elif(choice == 3): + task_index = int(input("Enter task index to mark completed (get it via printing tasks) : ")) + todo.mrk_task(task_index) + elif(choice == 4): + todo.prt_task() + elif(choice == 5): + exit(0) #exit condition + else: + print("Wrong choice !") + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/Chauhan_Shyam_R/Task_4/PDF_convert.py b/Chauhan_Shyam_R/Task_4/PDF_convert.py new file mode 100644 index 0000000..862beca --- /dev/null +++ b/Chauhan_Shyam_R/Task_4/PDF_convert.py @@ -0,0 +1,42 @@ +from pdf2jpg import pdf2jpg +from pypdf import PdfReader +import os + + + +class Pdf_to_image: + def __init__(self): + self.output_path = os.getcwd() + '\pdf2jpg' + + + def pdf_to_image(self,file_path): + pdf2jpg.convert_pdf2jpg(file_path, self.output_path, pages="ALL") + print("Done, all pages are converted check directory") + + +class Pdf_to_txt: + + def pdf_to_txt(self,file_path): + reader = PdfReader(file_path) + with open('ocr.txt','w') as f: + for i in range(1,len(reader.pages)): + page = reader.pages[i] + text = page.extract_text() + f.write(text) + print("Done, data saved in ocr.txt file") + +def main(): + choice = int(input("Enter your choice \n 1. Convert PDF to image \n 2. Convert PDF to txt \n 3. Exit \n Enter Number :")) + pdf_path = input("Enter full path of the PDF file : ") + if(choice == 1): + o = Pdf_to_image() + o.pdf_to_image(pdf_path) + elif(choice == 2): + o = Pdf_to_txt() + o.pdf_to_txt(pdf_path) + elif(choice == 3): + exit(0) + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/Chauhan_Shyam_R/Task_5/weather_app.py b/Chauhan_Shyam_R/Task_5/weather_app.py new file mode 100644 index 0000000..f6d8880 --- /dev/null +++ b/Chauhan_Shyam_R/Task_5/weather_app.py @@ -0,0 +1,19 @@ +import requests + +API_key = 'f4c6b56f806d4b3b2b26221c5805268a' + +def get_weather(city): + url = f'http://api.openweathermap.org/data/2.5/weather?q={city}&appid={API_key}&units=metric' + res = requests.get(url).json() + return res + + +def main(): + city = input("Enter city name to fetch weather info. : ") + data = get_weather(city) + print(f"Weather in {city}") + print(f"Temperature: {data['main']['temp']} °C") + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/Chauhan_Shyam_R/Task_6/web_scrapper.py b/Chauhan_Shyam_R/Task_6/web_scrapper.py new file mode 100644 index 0000000..88af76e --- /dev/null +++ b/Chauhan_Shyam_R/Task_6/web_scrapper.py @@ -0,0 +1,48 @@ +import requests +from bs4 import BeautifulSoup as bs4 +import csv + + + +def request_maker(): + headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' + } + url = 'https://books.toscrape.com/index.html' + res = requests.get(url, headers=headers) + soup = bs4(res.content, 'html5lib') + return soup + +def finder(soup): + books=[] + prices = [] + h3 = soup.find_all('h3') + price_tags = soup.find_all('p', class_='price_color') + + for price_tag in price_tags: + price = price_tag.text.strip() + prices.append(price) + + for book in h3: + i = book.find('a').get('title') + books.append(i) + return books,prices + +def csv_maker(data): + books,prices = data + file_name = 'book_data.csv' + with open(file_name,'w') as csv_file: + writer = csv.writer(csv_file) + writer.writerow(['Title', 'Price']) + for i in range(0,len(books)): + writer.writerow([books[i],prices[i]]) + print("csv file generated successfully, saved as book_data.csv") + + +def main(): + soup = request_maker() + data = finder(soup) + csv_maker(data) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/Chauhan_Shyam_R/Task_7/chatbot.py b/Chauhan_Shyam_R/Task_7/chatbot.py new file mode 100644 index 0000000..0e43c8e --- /dev/null +++ b/Chauhan_Shyam_R/Task_7/chatbot.py @@ -0,0 +1,48 @@ +# Enhanced rule-based chatbot with more responses +import random + +# Dictionary of predefined responses +responses = { + "hi": "Hello! How can I assist you today?", + "hello": "Hi there! How can I help?", + "how are you": "I'm doing well, thank you for asking!", + "what can you do": "I can provide information, answer questions, or just chat with you.", + "bye": "Goodbye! Have a great day!", + "thank you": "You're welcome!", + "default": "I'm sorry, I didn't quite understand that. Could you please rephrase?", + "weather": "The weather today is sunny with a high of 25°C.", + "time": "It's currently 2:30 PM.", + "help": "Sure, I can help! What do you need assistance with?", + "who are you": "I am a chatbot designed to assist you. How can I help today?", + "what is your name": "I don't have a name, but you can call me Chatbot!", + "who created you": "I was created by OpenAI using natural language processing techniques.", + "where are you from": "I exist in the digital realm, here to assist you wherever you are!", + "tell me a joke": "Why don't skeletons fight each other? They don't have the guts!", + "tell me a fact": "Did you know that honey never spoils? Archaeologists have found pots of honey in ancient Egyptian tombs that are over 3,000 years old and still perfectly edible!", + "what's up": "Not much, just here to assist you!", + "how old are you": "I don't have an age. I exist to help you whenever you need assistance!", + "what are you doing": "I'm here, ready to assist you with any questions or information you need!", + "tell me about yourself": "I am a chatbot created to assist users with information and questions. How can I assist you today?", + "good morning": "Good morning! How can I assist you today?", + "good afternoon": "Good afternoon! How can I assist you today?", + "good evening": "Good evening! How can I assist you today?" +} + +# Function to generate a response +def generate_response(user_input): + input_lower = user_input.lower() + if input_lower in responses: + return responses[input_lower] + else: + return responses["default"] + +# Main loop to run the chatbot +print("Welcome to the Chatbot!") +print("Type 'bye' to exit.") +while True: + user_input = input("You: ") + if user_input.lower() == 'bye': + print(generate_response(user_input)) + break + else: + print("Bot:", generate_response(user_input)) diff --git a/Chauhan_Shyam_R/Task_8/pdf_split.py b/Chauhan_Shyam_R/Task_8/pdf_split.py new file mode 100644 index 0000000..f64a9c3 --- /dev/null +++ b/Chauhan_Shyam_R/Task_8/pdf_split.py @@ -0,0 +1,24 @@ +from PyPDF2 import PdfReader, PdfWriter + +file_name = input("Enter the full path of the PDF file: ") +start_page = int(input("Enter the starting page number: ")) +end_page = int(input("Enter the ending page number: ")) + +reader = PdfReader(file_name) +total_pages = len(reader.pages) +writer = PdfWriter() +page_range = range(start_page, end_page + 1) + +if (end_page > total_pages): + print("End page value is greater than total pages !") + +else: + for page_num, page in enumerate(reader.pages, 1): + if page_num in page_range: + writer.add_page(page) + + output_file = f'{file_name}_page_{start_page}-{end_page}.pdf' + with open(output_file, 'wb') as out: + writer.write(out) + + print(f'Pages {start_page} to {end_page} extracted to {output_file}') diff --git a/Chauhan_Shyam_R/Task_9/image_convert.py b/Chauhan_Shyam_R/Task_9/image_convert.py new file mode 100644 index 0000000..af08ab6 --- /dev/null +++ b/Chauhan_Shyam_R/Task_9/image_convert.py @@ -0,0 +1,23 @@ +from PIL import Image + +# Function to get user's choice of format +def get_output_format(): + while True: + choice = input("Enter the desired output format (PNG, JPEG, BMP, GIF): ").strip().upper() + if choice in ['PNG', 'JPEG', 'BMP', 'GIF']: + return choice + else: + print("Invalid format. Please enter one of PNG, JPEG, BMP, GIF.") + +# Main code +image_path = input("Enter the full path of the PDF file: ") +image = Image.open(image_path) +image = image.convert('RGB') + +output_format = get_output_format() + +# Save the image based on user's choice +output_filename = f"converted-image.{output_format.lower()}" +image.save(output_filename) + +print(f"Image saved as {output_filename}") diff --git a/Chauhan_Shyam_R/task_3/guess_number.py b/Chauhan_Shyam_R/task_3/guess_number.py new file mode 100644 index 0000000..c8834db --- /dev/null +++ b/Chauhan_Shyam_R/task_3/guess_number.py @@ -0,0 +1,40 @@ +import random + +class guess_number: + def __init__(self): + self.temp = 0 #temp number to store user guess + self.range = 50 #defining range of number generator + + #number generator function + def number_generator(self): + return random.randint(0,self.range+1) + + + def user_guess(self,num): + ''' + User guess input and valoidator + param num: random number generated by function + ''' + print(num) + print("Guess the number between 0 to 50(inclusive)") + print("you will get 5 tries") + for i in range(0,5): + self.temp = int(input("Enter Your guess : ")) + if(self.temp > self.range): + print("Guess in between given range :/") + else: + if(self.temp == num): + print("Nice, Your guess is correct !") + exit(0) + else: + print("Wrong guess") + print("Out of tries !") + + +def main(): + print("Welcome to number guessing game !") + gs = guess_number() + gs.user_guess(gs.number_generator()) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/compressed_images/compressed_image.png b/compressed_images/compressed_image.png new file mode 100644 index 0000000..8c74af8 Binary files /dev/null and b/compressed_images/compressed_image.png differ