From 03145e321120729c3eebc923f52f9f336e6eba04 Mon Sep 17 00:00:00 2001 From: DeepaAjmeera <168549898+DeepaAjmeera@users.noreply.github.com> Date: Wed, 29 May 2024 11:44:13 +0530 Subject: [PATCH] Add files via upload --- PDF.py | 97 ++++++++++++++++++++++++++++++++++++++++++++ TodoList | 51 +++++++++++++++++++++++ number guessing game | 40 ++++++++++++++++++ simple calculator | 30 ++++++++++++++ 4 files changed, 218 insertions(+) create mode 100644 PDF.py create mode 100644 TodoList create mode 100644 number guessing game create mode 100644 simple calculator diff --git a/PDF.py b/PDF.py new file mode 100644 index 0000000..a102086 --- /dev/null +++ b/PDF.py @@ -0,0 +1,97 @@ +import PyPDF2 +import fitz # PyMuPDF +from docx import Document +from PIL import Image +from docx.shared import Pt +from docx.enum.text import WD_PARAGRAPH_ALIGNMENT + +def pdf_to_image(pdf_path, image_path): + pdf_document = fitz.open(pdf_path) + for page_number in range(len(pdf_document)): + page = pdf_document[page_number] + image = page.get_pixmap() + image.save(f"{image_path}_page_{page_number + 1}.png") + +def pdf_to_text(pdf_path, text_path): + with open(pdf_path, 'rb') as file: + reader = PyPDF2.PdfReader(file) + text = '' + for page_number in range(len(reader.pages)): + text += reader.pages[page_number].extract_text() + + with open(text_path, 'w', encoding='utf-8') as text_file: + text_file.write(text) + +def text_to_document(text_path, doc_path): + document = Document() + with open(text_path, 'r', encoding='utf-8') as text_file: + for line in text_file: + paragraph = document.add_paragraph(line.strip()) + paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT + run = paragraph.runs[0] + run.font.size = Pt(12) # Set font size to 12pt (adjust as needed) + # You can add more formatting options here + + document.save(doc_path) + +# Example usage +pdf_file = r"C:\Users\DELL\Downloads\kavya junuthula (3).pdf" +image_output_path =r"C:\Users\DELL\Downloads" +text_output_path=r"C:\Users\DELL\textfile.txt" +doc_output_path =r"C:\Users\DELL\document.docx" + +pdf_to_image(pdf_file, image_output_path) +pdf_to_text(pdf_file, text_output_path) +text_to_document(text_output_path, doc_output_path) +Footer +© 2024 GitHub, Inc. +Footer navigation +Terms +Privacy +Security +Status +import PyPDF2 +import fitz # PyMuPDF +from docx import Document +from PIL import Image +from docx.shared import Pt +from docx.enum.text import WD_PARAGRAPH_ALIGNMENT + +def pdf_to_image(pdf_path, image_path): + pdf_document = fitz.open(pdf_path) + for page_number in range(len(pdf_document)): + page = pdf_document[page_number] + image = page.get_pixmap() + image.save(f"{image_path}_page_{page_number + 1}.png") + +def pdf_to_text(pdf_path, text_path): + with open(pdf_path, 'rb') as file: + reader = PyPDF2.PdfReader(file) + text = '' + for page_number in range(len(reader.pages)): + text += reader.pages[page_number].extract_text() + + with open(text_path, 'w', encoding='utf-8') as text_file: + text_file.write(text) + +def text_to_document(text_path, doc_path): + document = Document() + with open(text_path, 'r', encoding='utf-8') as text_file: + for line in text_file: + paragraph = document.add_paragraph(line.strip()) + paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT + run = paragraph.runs[0] + run.font.size = Pt(12) # Set font size to 12pt (adjust as needed) + # You can add more formatting options here + + document.save(doc_path) + +# Example usage +pdf_file = r"C:\Users\DELL\Downloads\Deepa Ajmeera (3).pdf" +image_output_path =r"C:\Users\DELL\Downloads" +text_output_path=r"C:\Users\DELL\textfile.txt" +doc_output_path =r"C:\Users\DELL\document.docx" + +pdf_to_image(pdf_file, image_output_path) +pdf_to_text(pdf_file, text_output_path) +text_to_document(text_output_path, doc_output_path) diff --git a/TodoList b/TodoList new file mode 100644 index 0000000..845aa43 --- /dev/null +++ b/TodoList @@ -0,0 +1,51 @@ +class TodoList: + def __init__(self): + self.tasks = [] + + def add_task(self, task): + self.tasks.append(task) + print(f"Task '{task}' added to the to-do list.") + + def remove_task(self, task): + if task in self.tasks: + self.tasks.remove(task) + print(f"Task '{task}' removed from the to-do list.") + else: + print(f"Task '{task}' not found in the to-do list.") + + def show_tasks(self): + if self.tasks: + print("Your to-do list:") + for i, task in enumerate(self.tasks, start=1): + print(f"{i}. {task}") + else: + print("Your to-do list is empty.") + +def main(): + todo_list = TodoList() + + while True: + print("\nWhat would you like to do?") + print("1. Add task") + print("2. Remove task") + print("3. Show tasks") + print("4. Exit") + + choice = input("Enter your choice: ") + + if choice == '1': + task = input("Enter the task: ") + todo_list.add_task(task) + elif choice == '2': + task = input("Enter the task to remove: ") + todo_list.remove_task(task) + elif choice == '3': + todo_list.show_tasks() + elif choice == '4': + print("Exiting program...") + break + else: + print("Invalid choice. Please try again.") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/number guessing game b/number guessing game new file mode 100644 index 0000000..8fd61a1 --- /dev/null +++ b/number guessing game @@ -0,0 +1,40 @@ +import random +lower_bound = 1 +upper_bound = 1000 +max_attempts = 10 +secret_number = random.randint(lower_bound, upper_bound) +def get_guess(): + while True: + try: + guess = int(input(f"Guess a number between {lower_bound} and {upper_bound}: ")) + if lower_bound <= guess <= upper_bound: + return guess + else: + print("Invalid input. Please enter a number within the specified range.") + except ValueError: + print("Invalid input. Please enter a valid number.") +def check_guess(guess, secret_number): + if guess == secret_number: + return "Correct" + elif guess < secret_number: + return "Too low" + else: + return "Too high" +def play_game(): + attempts = 0 + won = False + while attempts < max_attempts: + attempts += 1 + guess = get_guess() + result = check_guess(guess, secret_number) + if result == "Correct": + print(f"Congratulations! You guessed the secret number {secret_number} in {attempts} attempts.") + won = True + break + else: + print(f"{result}. Try again!") + if not won: + print(f"Sorry, you ran out of attempts! The secret number is {secret_number}.") +if __name__ == "__main__": + print("Welcome to the Number Guessing Game!") + play_game() \ No newline at end of file diff --git a/simple calculator b/simple calculator new file mode 100644 index 0000000..53e64a5 --- /dev/null +++ b/simple calculator @@ -0,0 +1,30 @@ +def add(num1, num2): + return num1 + num2 +def subtract(num1, num2): + return num1 - num2 +def multiply(num1, num2): + return num1 * num2 +def divide(num1, num2): + return num1 / num2 +print("Please select operation -\n" + "1. Add\n" + "2. Subtract\n" + "3. Multiply\n" + "4. Divide\n") +select = int(input("Select operations form 1, 2, 3, 4 :")) +number_1 = int(input("Enter first number: ")) +number_2 = int(input("Enter second number: ")) +if select == 1: + print(number_1, "+", number_2, "=", + add(number_1, number_2)) +elif select == 2: + print(number_1, "-", number_2, "=", + subtract(number_1, number_2)) +elif select == 3: + print(number_1, "*", number_2, "=", + multiply(number_1, number_2)) +elif select == 4: + print(number_1, "/", number_2, "=", + divide(number_1, number_2)) +else: + print("Invalid input")