Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 29, 2024. It is now read-only.

Commit d72efd6

Browse files
Add files via upload
1 parent b693318 commit d72efd6

File tree

4 files changed

+187
-0
lines changed

4 files changed

+187
-0
lines changed

‎Task 1

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
def addition(x,y):
2+
return x+y
3+
4+
def subtraction(x,y):
5+
return x-y
6+
7+
def multiplication(x,y):
8+
return x*y
9+
10+
def division(x,y):
11+
if(y==0):
12+
return "Error! Devision by zero"
13+
else:
14+
return x/y
15+
16+
17+
18+
print("Operation.")
19+
20+
print("1. Addition.")
21+
print("2. Subtraction.")
22+
print("3. Multiplication.")
23+
print("4. Division.")
24+
25+
choice =input("Enter your Choice: ")
26+
27+
num1 = float(input("Enter number first : "))
28+
num2 = float(input("Enter number second : "))
29+
30+
if choice == "1":
31+
print("Result : ", addition(num1 , num2))
32+
elif choice == "2":
33+
print("Result : ", subtraction(num1 , num2))
34+
elif choice == "3":
35+
print("Result : ", multiplication(num1 , num2))
36+
elif choice == "4":
37+
print("Result : ", division(num1 , num2))
38+
else:
39+
print("Invalid input.")

‎Task 2

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
class TaskManager:
2+
def __init__(self):
3+
self.tasks = []
4+
5+
def add_task(self, task):
6+
self.tasks.append(task)
7+
print("Task added successfully.")
8+
9+
def delete_task(self, task_index):
10+
if task_index < len(self.tasks):
11+
del self.tasks[task_index]
12+
print("Task deleted successfully.")
13+
else:
14+
print("Invalid task index.")
15+
16+
def mark_completed(self, task_index):
17+
if task_index < len(self.tasks):
18+
self.tasks[task_index]['completed'] = True
19+
print("Task marked as completed.")
20+
else:
21+
print("Invalid task index.")
22+
23+
def display_tasks(self):
24+
print("\nTasks:")
25+
for index, task in enumerate(self.tasks):
26+
print(f"{index + 1}. {task['description']} - {'Completed' if task['completed'] else 'Pending'}")
27+
28+
29+
def main():
30+
task_manager = TaskManager()
31+
32+
while True:
33+
print("\nTask Manager")
34+
print("1. Add Task")
35+
print("2. Delete Task")
36+
print("3. Mark Task as Completed")
37+
print("4. Display Tasks")
38+
print("5. Exit")
39+
40+
choice = input("Enter your choice: ")
41+
42+
if choice == '1':
43+
description = input("Enter task description: ")
44+
task_manager.add_task({'description': description, 'completed': False})
45+
elif choice == '2':
46+
task_index = int(input("Enter index of task to delete: ")) - 1
47+
task_manager.delete_task(task_index)
48+
elif choice == '3':
49+
task_index = int(input("Enter index of task to mark as completed: ")) - 1
50+
task_manager.mark_completed(task_index)
51+
elif choice == '4':
52+
task_manager.display_tasks()
53+
elif choice == '5':
54+
print("Exiting...")
55+
break
56+
else:
57+
print("Invalid choice. Please try again.")
58+
59+
60+
if __name__ == "__main__":
61+
main()

‎Task 3

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import random
2+
3+
def guess_number():
4+
# Generate a random number between 1 and 100
5+
secret_number = random.randint(1, 100)
6+
attempts = 0
7+
max_attempts = 10
8+
# You can adjust this value as needed
9+
10+
print("Welcome to the Number Guessing Game!")
11+
print("I have chosen a number between 1 and 100. You have", max_attempts, "attempts to guess it.")
12+
13+
while attempts < max_attempts:
14+
try:
15+
guess = int(input("Enter your guess: "))
16+
except ValueError:
17+
print("Please enter a valid number.")
18+
continue
19+
20+
attempts += 1
21+
22+
if guess < secret_number:
23+
print("Too low! Try again.")
24+
elif guess > secret_number:
25+
print("Too high! Try again.")
26+
else:
27+
print("Congratulations! You've guessed the number", secret_number, "correctly in", attempts, "attempts!")
28+
break
29+
else:
30+
print("Sorry, you've run out of attempts. The number was:", secret_number)
31+
32+
# Run the game
33+
guess_number()

‎Task 4

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import PyPDF2
2+
import fitz
3+
import os
4+
5+
def pdf_to_text(pdf_file, output_folder):
6+
# Open the PDF file
7+
with open(pdf_file, 'rb') as file:
8+
pdf_reader = PyPDF2.PdfFileReader(file)
9+
10+
# Create output folder if it doesn't exist
11+
if not os.path.exists(output_folder):
12+
os.makedirs(output_folder)
13+
14+
# Extract text from each page
15+
for page_num in range(pdf_reader.numPages):
16+
page = pdf_reader.getPage(page_num)
17+
text = page.extractText()
18+
19+
# Write extracted text to a text file
20+
text_file_path = os.path.join(output_folder, f"page_{page_num + 1}.txt")
21+
with open(text_file_path, 'w') as text_file:
22+
text_file.write(text)
23+
24+
print("Text extraction completed. Text files saved in:", output_folder)
25+
26+
def pdf_to_images(pdf_file, output_folder):
27+
# Open the PDF file
28+
pdf_document = fitz.open(pdf_file)
29+
30+
# Create output folder if it doesn't exist
31+
if not os.path.exists(output_folder):
32+
os.makedirs(output_folder)
33+
34+
# Iterate through each page and save as image
35+
for page_num in range(len(pdf_document)):
36+
page = pdf_document[page_num]
37+
image_path = os.path.join(output_folder, f"page_{page_num + 1}.png")
38+
pix = page.get_pixmap()
39+
pix.writePNG(image_path)
40+
41+
print("Image conversion completed. Images saved in:", output_folder)
42+
43+
def main():
44+
pdf_file = 'sample.pdf' # Change this to the path of your PDF file
45+
output_folder = 'output' # Output folder where converted files will be saved
46+
47+
# Convert PDF to text
48+
pdf_to_text(pdf_file, output_folder)
49+
50+
# Convert PDF to images
51+
pdf_to_images(pdf_file, output_folder)
52+
53+
if __name__ == "__main__":
54+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /