From f9d9e2306d24028cf5e5431cce8dc9bd719ff479 Mon Sep 17 00:00:00 2001 From: nandu888 Date: Thu, 20 Jun 2024 12:09:58 +0530 Subject: [PATCH 1/6] Create README.md and completed task1 --- ch_nandu/README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 ch_nandu/README.md diff --git a/ch_nandu/README.md b/ch_nandu/README.md new file mode 100644 index 0000000..a4c9d4a --- /dev/null +++ b/ch_nandu/README.md @@ -0,0 +1,30 @@ +#a simple python program to perform basic tasks like addition,subtraction,multiplication,division +print('please select any of the number for performing arithmetic operations') +print("1.Addition") +print('2.Subtraction') +print('3.Multiplication') +print('4.Division') +print('5.exit') +a=int(input('Enter any of the number for performing arithmetic operations')) +def ari(a,var1,var2): + a,var1,var2=a,var1,var2 + if(a==1): + print(var1+var2) + if(a==2): + print(var1-var2) + if(a==3): + print(var1*var2) + if(a==4): + print(var1/var2) + return + +#Enter Two numbers +if((a>0) and (a<5)): + var1 = int(input('Enter First number: ')) + var2 = int(input('Enter Second number: ')) + ari(a,var1,var2) +elif(a==5): + exit() +else: + print('Invalid Option') + print('please select 1/2/3/4/5 only') From 00877be6dc35fdb07ac9d333bb93768202ae86ac Mon Sep 17 00:00:00 2001 From: nandu888 Date: Thu, 20 Jun 2024 12:12:53 +0530 Subject: [PATCH 2/6] Create task2.py and completed task2 --- ch_nandu/task2/task2.py | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 ch_nandu/task2/task2.py diff --git a/ch_nandu/task2/task2.py b/ch_nandu/task2/task2.py new file mode 100644 index 0000000..1eacb0a --- /dev/null +++ b/ch_nandu/task2/task2.py @@ -0,0 +1,59 @@ +class TaskManager: + def __init__(self): + self.tasks = [] + + def add_task(self, task): + self.tasks.append({"task": task, "completed": False}) + + def delete_task(self, index): + if 0 <= index < len(self.tasks): + del self.tasks[index] + else: + print("Invalid task index") + + def mark_task_completed(self, index): + if 0 <= index < len(self.tasks): + self.tasks[index]["completed"] = True + else: + print("Invalid task index") + + def display_tasks(self): + print("Tasks:") + for i, task in enumerate(self.tasks): + status = "Completed" if task["completed"] else "Pending" + print(f"{i+1}. {task['task']} - {status}") + + +def main(): + task_manager = TaskManager() + + while True: + print("\nOptions:") + print("1. Add Task") + print("2. Delete Task") + print("3. Mark Task as Completed") + print("4. View Tasks") + print("5. Exit") + + choice = input("Enter your choice: ") + + if choice == "1": + task = input("Enter the task: ") + task_manager.add_task(task) + elif choice == "2": + index = int(input("Enter the index of the task to delete: ")) - 1 + task_manager.delete_task(index) + elif choice == "3": + index = int(input("Enter the index of the task to mark as completed: ")) - 1 + task_manager.mark_task_completed(index) + elif choice == "4": + task_manager.display_tasks() + elif choice == "5": + print("Exiting...") + break + else: + print("Invalid choice. Please try again.") + + +if __name__ == "__main__": + main() From aadb2ea6ce91b0e4f9d807653325e3cad3fd5c90 Mon Sep 17 00:00:00 2001 From: nandu888 Date: Thu, 20 Jun 2024 12:13:55 +0530 Subject: [PATCH 3/6] Create task3.py and completed task3 --- ch_nandu/task3/task3.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 ch_nandu/task3/task3.py diff --git a/ch_nandu/task3/task3.py b/ch_nandu/task3/task3.py new file mode 100644 index 0000000..f1bc4c2 --- /dev/null +++ b/ch_nandu/task3/task3.py @@ -0,0 +1,33 @@ +import random + +def guess_number(): + # Generate a random number between 1 and 100 + secret_number = random.randint(1, 100) + attempts = 0 + max_attempts = 10 + + print("Welcome to the Number Guessing Game!") + print("I have chosen a number between 1 and 100. You have", max_attempts, "attempts to guess it.") + + while attempts < max_attempts: + try: + guess = int(input("Enter your guess: ")) + except ValueError: + print("Invalid input! Please enter a valid number.") + continue + + attempts += 1 + + if guess < secret_number: + print("Too low! Try again.") + elif guess > secret_number: + print("Too high! Try again.") + else: + print("Congratulations! You've guessed the number", secret_number, "correctly in", attempts, "attempts!") + break + else: + print("Sorry, you've run out of attempts. The correct number was", secret_number) + +if __name__ == "__main__": + guess_number() + From 8a202dfe4fe29ed70fc4b0ef0f49d0b15b0b1997 Mon Sep 17 00:00:00 2001 From: nandu888 Date: Thu, 20 Jun 2024 12:14:56 +0530 Subject: [PATCH 4/6] Create task1.py and created task1 --- ch_nandu/task1/task1.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 ch_nandu/task1/task1.py diff --git a/ch_nandu/task1/task1.py b/ch_nandu/task1/task1.py new file mode 100644 index 0000000..a4c9d4a --- /dev/null +++ b/ch_nandu/task1/task1.py @@ -0,0 +1,30 @@ +#a simple python program to perform basic tasks like addition,subtraction,multiplication,division +print('please select any of the number for performing arithmetic operations') +print("1.Addition") +print('2.Subtraction') +print('3.Multiplication') +print('4.Division') +print('5.exit') +a=int(input('Enter any of the number for performing arithmetic operations')) +def ari(a,var1,var2): + a,var1,var2=a,var1,var2 + if(a==1): + print(var1+var2) + if(a==2): + print(var1-var2) + if(a==3): + print(var1*var2) + if(a==4): + print(var1/var2) + return + +#Enter Two numbers +if((a>0) and (a<5)): + var1 = int(input('Enter First number: ')) + var2 = int(input('Enter Second number: ')) + ari(a,var1,var2) +elif(a==5): + exit() +else: + print('Invalid Option') + print('please select 1/2/3/4/5 only') From 6effc00aa70227751b38606d0ea2b34de39af038 Mon Sep 17 00:00:00 2001 From: nandu888 Date: Thu, 20 Jun 2024 12:16:38 +0530 Subject: [PATCH 5/6] Create task4.py and completed task4 --- ch_nandu/task4/task4.py | 93 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 ch_nandu/task4/task4.py diff --git a/ch_nandu/task4/task4.py b/ch_nandu/task4/task4.py new file mode 100644 index 0000000..2b9f9ea --- /dev/null +++ b/ch_nandu/task4/task4.py @@ -0,0 +1,93 @@ +import PyPDF2 +from PIL import Image +import os + + +def convert_pdf_to_text(pdf_path, text_output_path): + """Converts a PDF file to text. + + Args: + pdf_path (str): Path to the input PDF file. + text_output_path (str): Path to save the converted text file. + """ + try: + with open(pdf_path, 'rb') as pdf_file: + pdf_reader = PyPDF2.PdfReader(pdf_file) + with open(text_output_path, 'w', encoding='utf-8') as text_file: + # Iterate through each page of the PDF + for page_num in range(len(pdf_reader.pages)): + page = pdf_reader.pages[page_num] + # Extract text from the page and write it to the text file + text_file.write(page.extract_text()) + print(f"PDF converted to text successfully. Text file saved at {text_output_path}") + except Exception as e: + print(f"An error occurred: {e}") + + +def extract_images_from_pdf(pdf_path, image_output_folder): + """Extracts images from a PDF file. + + Args: + pdf_path (str): Path to the input PDF file. + image_output_folder (str): Folder to save the extracted images. + """ + try: + with open(pdf_path, 'rb') as pdf_file: + pdf_reader = PyPDF2.PdfReader(pdf_file) + # Iterate through each page of the PDF + for page_num in range(len(pdf_reader.pages)): + page = pdf_reader.pages[page_num] + xObject = page['/Resources']['/XObject'].getObject() + for obj in xObject: + if xObject[obj]['/Subtype'] == '/Image': + size = (xObject[obj]['/Width'], xObject[obj]['/Height']) + data = xObject[obj]._data + mode = '' + if xObject[obj]['/ColorSpace'] == '/DeviceRGB': + mode = "RGB" + else: + mode = "P" + if xObject[obj]['/Filter'] == '/FlateDecode': + img = Image.frombytes(mode, size, data) + img.save(os.path.join(image_output_folder, f"page{page_num+1}_{obj[1:]}.png")) + elif xObject[obj]['/Filter'] == '/DCTDecode': + img = open(os.path.join(image_output_folder, f"page{page_num+1}_{obj[1:]}.jpg"), "wb") + img.write(data) + img.close() + elif xObject[obj]['/Filter'] == '/JPXDecode': + img = open(os.path.join(image_output_folder, f"page{page_num+1}_{obj[1:]}.jp2"), "wb") + img.write(data) + img.close() + print(f"Images extracted successfully. Saved in {image_output_folder}") + except Exception as e: + print(f"An error occurred: {e}") + + +def main(): + # Get input paths and output folder from user + pdf_path = input("Enter the path to the PDF file: ") + output_folder = input("Enter the output folder path: ") + + # Create the output folder if it does not exist + if not os.path.exists(output_folder): + os.makedirs(output_folder) + + # Choose conversion option + choice = input("Choose an option:\n1. Convert PDF to text\n2. Extract images from PDF\nEnter your choice: ") + + if choice == '1': + # Convert PDF to text + text_output_path = os.path.join(output_folder, "converted_text.txt") + convert_pdf_to_text(pdf_path, text_output_path) + elif choice == '2': + # Extract images from PDF + image_output_folder = os.path.join(output_folder, "extracted_images") + if not os.path.exists(image_output_folder): + os.makedirs(image_output_folder) + extract_images_from_pdf(pdf_path, image_output_folder) + else: + print("Invalid choice. Please choose 1 or 2.") + + +if __name__ == "__main__": + main() From 4502bbbaddfa54f5407b47b35d12d1ab9cf162ae Mon Sep 17 00:00:00 2001 From: nandu888 Date: Thu, 20 Jun 2024 12:20:01 +0530 Subject: [PATCH 6/6] Delete ch_nandu/README.md --- ch_nandu/README.md | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 ch_nandu/README.md diff --git a/ch_nandu/README.md b/ch_nandu/README.md deleted file mode 100644 index a4c9d4a..0000000 --- a/ch_nandu/README.md +++ /dev/null @@ -1,30 +0,0 @@ -#a simple python program to perform basic tasks like addition,subtraction,multiplication,division -print('please select any of the number for performing arithmetic operations') -print("1.Addition") -print('2.Subtraction') -print('3.Multiplication') -print('4.Division') -print('5.exit') -a=int(input('Enter any of the number for performing arithmetic operations')) -def ari(a,var1,var2): - a,var1,var2=a,var1,var2 - if(a==1): - print(var1+var2) - if(a==2): - print(var1-var2) - if(a==3): - print(var1*var2) - if(a==4): - print(var1/var2) - return - -#Enter Two numbers -if((a>0) and (a<5)): - var1 = int(input('Enter First number: ')) - var2 = int(input('Enter Second number: ')) - ari(a,var1,var2) -elif(a==5): - exit() -else: - print('Invalid Option') - print('please select 1/2/3/4/5 only')