diff --git a/calculator1.py b/calculator1.py new file mode 100644 index 0000000..738c193 --- /dev/null +++ b/calculator1.py @@ -0,0 +1,55 @@ +# This function adds two numbers +def add(x, y): + return x + y + +# This function subtracts two numbers +def subtract(x, y): + return x - y + +# This function multiplies two numbers +def multiply(x, y): + return x * y + +# This function divides two numbers +def divide(x, y): + return x / y + + +print("Select operation.") +print("1.Add") +print("2.Subtract") +print("3.Multiply") +print("4.Divide") + +while True: + # take input from the user + choice = input("Enter choice(1/2/3/4): ") + + # check if choice is one of the four options + if choice in ('1', '2', '3', '4'): + try: + num1 = float(input("Enter first number: ")) + num2 = float(input("Enter second number: ")) + except ValueError: + print("Invalid input. Please enter a number.") + continue + + if choice == '1': + print(num1, "+", num2, "=", add(num1, num2)) + + elif choice == '2': + print(num1, "-", num2, "=", subtract(num1, num2)) + + elif choice == '3': + print(num1, "*", num2, "=", multiply(num1, num2)) + + elif choice == '4': + print(num1, "/", num2, "=", divide(num1, num2)) + + # check if user wants another calculation + # break the while loop if answer is no + next_calculation = input("Let's do next calculation? (yes/no): ") + if next_calculation == "no": + break + else: + print("Invalid Input") \ No newline at end of file diff --git a/numberguessing.py b/numberguessing.py new file mode 100644 index 0000000..1f8ec66 --- /dev/null +++ b/numberguessing.py @@ -0,0 +1,32 @@ +import random + +def number_guessing_game(low, high, max_attempts): + number_to_guess = random.randint(low, high) + attempts = 0 + + print(f"Guess the number between {low} and {high}. You have {max_attempts} attempts.") + + while attempts < max_attempts: + attempts += 1 + user_guess = input("Enter your guess: ") + + try: + user_guess = int(user_guess) + except ValueError: + print("Please enter a valid integer.") + continue + + if user_guess == number_to_guess: + print(f"Congratulations! You've guessed the right number in {attempts} attempts.") + break + elif user_guess < number_to_guess: + print("Try again! You guessed too low.") + else: + print("Try again! You guessed too high.") + + if attempts == max_attempts: + print(f"Sorry, you've used all your attempts. The number was {number_to_guess}.") + break + +# Start the game +number_guessing_game(1, 100, 10) diff --git a/pdf.py b/pdf.py new file mode 100644 index 0000000..5009f2e --- /dev/null +++ b/pdf.py @@ -0,0 +1,46 @@ +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\Roshini Khammam.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/todolists.py b/todolists.py new file mode 100644 index 0000000..c0984f2 --- /dev/null +++ b/todolists.py @@ -0,0 +1,44 @@ +import json +import os + +def display_menu(): + print("Todo List Menu:") + print("1. Add task") + print("2. Remove task") + print("3. View tasks") + print("4. Exit") + +def main(): + tasks = [] + + while True: + display_menu() + choice = input("Enter your choice: ") + + if choice == "1": + task = input("Enter a new task: ") + tasks.append(task) + print("Task added.") + + elif choice == "2": + task = input("Enter the task to remove: ") + + if task in tasks: + tasks.remove(task) + print("Task removed.") + else: + print("Task not found.") + + elif choice == "3": + print("Tasks:") + for task in tasks: + print("- " + task) + + elif choice == "4": + break + + else: + print("Invalid choice. Please try again.") + +if __name__ == "__main__": + main()