Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Beginner Level #47

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions PDF.py
Original file line number Diff line number Diff line change
@@ -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)
51 changes: 51 additions & 0 deletions TodoList
Original file line number Diff line number Diff line change
@@ -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()
40 changes: 40 additions & 0 deletions number guessing game
Original file line number Diff line number Diff line change
@@ -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()
30 changes: 30 additions & 0 deletions simple calculator
Original file line number Diff line number Diff line change
@@ -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")