Skip to content

Commit 03145e3

Browse files
authored
Add files via upload
1 parent b5be041 commit 03145e3

File tree

4 files changed

+218
-0
lines changed

4 files changed

+218
-0
lines changed

PDF.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import PyPDF2
2+
import fitz # PyMuPDF
3+
from docx import Document
4+
from PIL import Image
5+
from docx.shared import Pt
6+
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
7+
8+
def pdf_to_image(pdf_path, image_path):
9+
pdf_document = fitz.open(pdf_path)
10+
for page_number in range(len(pdf_document)):
11+
page = pdf_document[page_number]
12+
image = page.get_pixmap()
13+
image.save(f"{image_path}_page_{page_number + 1}.png")
14+
15+
def pdf_to_text(pdf_path, text_path):
16+
with open(pdf_path, 'rb') as file:
17+
reader = PyPDF2.PdfReader(file)
18+
text = ''
19+
for page_number in range(len(reader.pages)):
20+
text += reader.pages[page_number].extract_text()
21+
22+
with open(text_path, 'w', encoding='utf-8') as text_file:
23+
text_file.write(text)
24+
25+
def text_to_document(text_path, doc_path):
26+
document = Document()
27+
with open(text_path, 'r', encoding='utf-8') as text_file:
28+
for line in text_file:
29+
paragraph = document.add_paragraph(line.strip())
30+
paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
31+
run = paragraph.runs[0]
32+
run.font.size = Pt(12) # Set font size to 12pt (adjust as needed)
33+
# You can add more formatting options here
34+
35+
document.save(doc_path)
36+
37+
# Example usage
38+
pdf_file = r"C:\Users\DELL\Downloads\kavya junuthula (3).pdf"
39+
image_output_path =r"C:\Users\DELL\Downloads"
40+
text_output_path=r"C:\Users\DELL\textfile.txt"
41+
doc_output_path =r"C:\Users\DELL\document.docx"
42+
43+
pdf_to_image(pdf_file, image_output_path)
44+
pdf_to_text(pdf_file, text_output_path)
45+
text_to_document(text_output_path, doc_output_path)
46+
Footer
47+
© 2024 GitHub, Inc.
48+
Footer navigation
49+
Terms
50+
Privacy
51+
Security
52+
Status
53+
import PyPDF2
54+
import fitz # PyMuPDF
55+
from docx import Document
56+
from PIL import Image
57+
from docx.shared import Pt
58+
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
59+
60+
def pdf_to_image(pdf_path, image_path):
61+
pdf_document = fitz.open(pdf_path)
62+
for page_number in range(len(pdf_document)):
63+
page = pdf_document[page_number]
64+
image = page.get_pixmap()
65+
image.save(f"{image_path}_page_{page_number + 1}.png")
66+
67+
def pdf_to_text(pdf_path, text_path):
68+
with open(pdf_path, 'rb') as file:
69+
reader = PyPDF2.PdfReader(file)
70+
text = ''
71+
for page_number in range(len(reader.pages)):
72+
text += reader.pages[page_number].extract_text()
73+
74+
with open(text_path, 'w', encoding='utf-8') as text_file:
75+
text_file.write(text)
76+
77+
def text_to_document(text_path, doc_path):
78+
document = Document()
79+
with open(text_path, 'r', encoding='utf-8') as text_file:
80+
for line in text_file:
81+
paragraph = document.add_paragraph(line.strip())
82+
paragraph.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
83+
run = paragraph.runs[0]
84+
run.font.size = Pt(12) # Set font size to 12pt (adjust as needed)
85+
# You can add more formatting options here
86+
87+
document.save(doc_path)
88+
89+
# Example usage
90+
pdf_file = r"C:\Users\DELL\Downloads\Deepa Ajmeera (3).pdf"
91+
image_output_path =r"C:\Users\DELL\Downloads"
92+
text_output_path=r"C:\Users\DELL\textfile.txt"
93+
doc_output_path =r"C:\Users\DELL\document.docx"
94+
95+
pdf_to_image(pdf_file, image_output_path)
96+
pdf_to_text(pdf_file, text_output_path)
97+
text_to_document(text_output_path, doc_output_path)

TodoList

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
class TodoList:
2+
def __init__(self):
3+
self.tasks = []
4+
5+
def add_task(self, task):
6+
self.tasks.append(task)
7+
print(f"Task '{task}' added to the to-do list.")
8+
9+
def remove_task(self, task):
10+
if task in self.tasks:
11+
self.tasks.remove(task)
12+
print(f"Task '{task}' removed from the to-do list.")
13+
else:
14+
print(f"Task '{task}' not found in the to-do list.")
15+
16+
def show_tasks(self):
17+
if self.tasks:
18+
print("Your to-do list:")
19+
for i, task in enumerate(self.tasks, start=1):
20+
print(f"{i}. {task}")
21+
else:
22+
print("Your to-do list is empty.")
23+
24+
def main():
25+
todo_list = TodoList()
26+
27+
while True:
28+
print("\nWhat would you like to do?")
29+
print("1. Add task")
30+
print("2. Remove task")
31+
print("3. Show tasks")
32+
print("4. Exit")
33+
34+
choice = input("Enter your choice: ")
35+
36+
if choice == '1':
37+
task = input("Enter the task: ")
38+
todo_list.add_task(task)
39+
elif choice == '2':
40+
task = input("Enter the task to remove: ")
41+
todo_list.remove_task(task)
42+
elif choice == '3':
43+
todo_list.show_tasks()
44+
elif choice == '4':
45+
print("Exiting program...")
46+
break
47+
else:
48+
print("Invalid choice. Please try again.")
49+
50+
if __name__ == "__main__":
51+
main()

number guessing game

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import random
2+
lower_bound = 1
3+
upper_bound = 1000
4+
max_attempts = 10
5+
secret_number = random.randint(lower_bound, upper_bound)
6+
def get_guess():
7+
while True:
8+
try:
9+
guess = int(input(f"Guess a number between {lower_bound} and {upper_bound}: "))
10+
if lower_bound <= guess <= upper_bound:
11+
return guess
12+
else:
13+
print("Invalid input. Please enter a number within the specified range.")
14+
except ValueError:
15+
print("Invalid input. Please enter a valid number.")
16+
def check_guess(guess, secret_number):
17+
if guess == secret_number:
18+
return "Correct"
19+
elif guess < secret_number:
20+
return "Too low"
21+
else:
22+
return "Too high"
23+
def play_game():
24+
attempts = 0
25+
won = False
26+
while attempts < max_attempts:
27+
attempts += 1
28+
guess = get_guess()
29+
result = check_guess(guess, secret_number)
30+
if result == "Correct":
31+
print(f"Congratulations! You guessed the secret number {secret_number} in {attempts} attempts.")
32+
won = True
33+
break
34+
else:
35+
print(f"{result}. Try again!")
36+
if not won:
37+
print(f"Sorry, you ran out of attempts! The secret number is {secret_number}.")
38+
if __name__ == "__main__":
39+
print("Welcome to the Number Guessing Game!")
40+
play_game()

simple calculator

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
def add(num1, num2):
2+
return num1 + num2
3+
def subtract(num1, num2):
4+
return num1 - num2
5+
def multiply(num1, num2):
6+
return num1 * num2
7+
def divide(num1, num2):
8+
return num1 / num2
9+
print("Please select operation -\n"
10+
"1. Add\n"
11+
"2. Subtract\n"
12+
"3. Multiply\n"
13+
"4. Divide\n")
14+
select = int(input("Select operations form 1, 2, 3, 4 :"))
15+
number_1 = int(input("Enter first number: "))
16+
number_2 = int(input("Enter second number: "))
17+
if select == 1:
18+
print(number_1, "+", number_2, "=",
19+
add(number_1, number_2))
20+
elif select == 2:
21+
print(number_1, "-", number_2, "=",
22+
subtract(number_1, number_2))
23+
elif select == 3:
24+
print(number_1, "*", number_2, "=",
25+
multiply(number_1, number_2))
26+
elif select == 4:
27+
print(number_1, "/", number_2, "=",
28+
divide(number_1, number_2))
29+
else:
30+
print("Invalid input")

0 commit comments

Comments
 (0)