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 afd3870

Browse files
Added my internship projects
1 parent a26052d commit afd3870

File tree

4 files changed

+190
-0
lines changed

4 files changed

+190
-0
lines changed

‎thattururajitha/number_guessing‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#NUmber guessing game
2+
"""
3+
Below is a Python implementation of a Number Guessing Game
4+
where the computer generates a random number,
5+
and the player tries to guess it within a certain number of attempts.
6+
we can import random nubers as our wish. Here I take the numbers
7+
betwenn 1 to 50 , we can import as we wish.
8+
"""
9+
import random
10+
11+
def play_guessing_game():
12+
# Generate a random number between 1 and 50
13+
secret_number = random.randint(1, 50)
14+
max_attempts = 10
15+
attempts = 0
16+
17+
print("Welcome to the Number Guessing Game!")
18+
print(f"I'm thinking of a number between 1 and 100. Can you guess it?")
19+
20+
while attempts < max_attempts:
21+
try:
22+
guess = int(input("Enter your guess: "))
23+
attempts += 1
24+
25+
if guess == secret_number:
26+
print(f"Congratulations! You guessed it right in {attempts} attempts.")
27+
break
28+
elif guess < secret_number:
29+
print("Try a higher number.")
30+
else:
31+
print("Try a lower number.")
32+
33+
except ValueError:
34+
print("Invalid input. Please enter a valid integer.")
35+
36+
if attempts == max_attempts:
37+
print(f"Sorry, you've reached the maximum number of attempts. The secret number was {secret_number}.")
38+
39+
if __name__ == "__main__":
40+
play_guessing_game()

‎thattururajitha/pdf_converter.py‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import os
2+
import fitz # PyMuPDF library for working with PDFs
3+
from PIL import Image
4+
5+
def convert_pdf_to_text(pdf_path, text_path):
6+
"""
7+
Converts a PDF file to plain text and saves it to a text file.
8+
:param pdf_path: Path to the input PDF file
9+
:param text_path: Path to save the output text file
10+
"""
11+
try:
12+
doc = fitz.open(pdf_path)
13+
text = ""
14+
for page in doc:
15+
text += page.get_text("text")
16+
with open(text_path, "w", encoding="utf-8") as txt_file:
17+
txt_file.write(text)
18+
print(f"Text extracted and saved to {text_path}")
19+
except Exception as e:
20+
print(f"Error converting PDF to text: {e}")
21+
22+
def convert_pdf_to_images(pdf_path, images_folder):
23+
"""
24+
Converts each page of a PDF to images (PNG format) and saves them to a specified folder.
25+
:param pdf_path: Path to the input PDF file
26+
:param images_folder: Folder to save the output images
27+
"""
28+
try:
29+
doc = fitz.open(pdf_path)
30+
os.makedirs(images_folder, exist_ok=True)
31+
for page_num, page in enumerate(doc):
32+
image_path = os.path.join(images_folder, f"page_{page_num + 1}.png")
33+
pix = page.get_pixmap(matrix=fitz.Matrix(2, 2)) # Increase resolution for better quality
34+
img = Image.frombytes("RGB", (pix.width, pix.height), pix.samples)
35+
img.save(image_path, format="PNG")
36+
print(f"Images saved to {images_folder}")
37+
except Exception as e:
38+
print(f"Error converting PDF to images: {e}")
39+
40+
# Example usage:
41+
if __name__ == "__main__":
42+
input_pdf = "example.pdf"
43+
output_text = "example.txt"
44+
output_images = "images"
45+
46+
convert_pdf_to_text(input_pdf, output_text)
47+
convert_pdf_to_images(input_pdf, output_images)

‎thattururajitha/simple_calculator‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
def add(x, y):
2+
"""Function to add two numbers"""
3+
return x + y
4+
5+
def subtract(x, y):
6+
"""Function to subtract two numbers"""
7+
return x - y
8+
9+
def multiply(x, y):
10+
"""Function to multiply two numbers"""
11+
return x * y
12+
13+
def divide(x, y):
14+
"""Function to divide two numbers"""
15+
if y != 0:
16+
return x / y
17+
else:
18+
return "Error: Cannot divide by zero"
19+
20+
def main():
21+
print("Simple Calculator")
22+
print("Available operations:")
23+
print("1. Add")
24+
print("2. Subtract")
25+
print("3. Multiply")
26+
print("4. Divide")
27+
28+
choice = input("Enter your choice (1/2/3/4): ")
29+
30+
num1 = float(input("Enter the first number: "))
31+
num2 = float(input("Enter the second number: "))
32+
33+
if choice == '1':
34+
print(f"Result: {num1} + {num2} = {add(num1, num2)}")
35+
elif choice == '2':
36+
print(f"Result: {num1} - {num2} = {subtract(num1, num2)}")
37+
elif choice == '3':
38+
print(f"Result: {num1} * {num2} = {multiply(num1, num2)}")
39+
elif choice == '4':
40+
print(f"Result: {num1} / {num2} = {divide(num1, num2)}")
41+
else:
42+
print("Invalid choice. Please select a valid operation (1/2/3/4).")
43+
44+
if __name__ == "__main__":
45+
main()

‎thattururajitha/to_dolist‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 successfully!")
8+
9+
def delete_task(self, task):
10+
if task in self.tasks:
11+
self.tasks.remove(task)
12+
print(f"Task '{task}' deleted successfully!")
13+
else:
14+
print(f"Task '{task}' not found.")
15+
16+
def mark_completed(self, task):
17+
if task in self.tasks:
18+
print(f"Task '{task}' marked as completed!")
19+
else:
20+
print(f"Task '{task}' not found.")
21+
22+
def display_tasks(self):
23+
print("\nCurrent tasks:")
24+
for i, task in enumerate(self.tasks, start=1):
25+
print(f"{i}. {task}")
26+
27+
def main():
28+
todo = ToDoList()
29+
30+
while True:
31+
print("\nMenu:")
32+
print("1. Add Task")
33+
print("2. Delete Task")
34+
print("3. Mark Task as Completed")
35+
print("4. Display Tasks")
36+
print("5. Exit")
37+
38+
choice = input("Enter your choice (1/2/3/4/5): ")
39+
40+
if choice == '1':
41+
task = input("Enter the task: ")
42+
todo.add_task(task)
43+
elif choice == '2':
44+
task = input("Enter the task to delete: ")
45+
todo.delete_task(task)
46+
elif choice == '3':
47+
task = input("Enter the task to mark as completed: ")
48+
todo.mark_completed(task)
49+
elif choice == '4':
50+
todo.display_tasks()
51+
elif choice == '5':
52+
print("Exiting the application. Have a great day!")
53+
break
54+
else:
55+
print("Invalid choice. Please select a valid option.")
56+
57+
if __name__ == "__main__":
58+
main()

0 commit comments

Comments
(0)

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