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

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: CSEdgeOfficial/Python-Programming-Internship
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: cherry-420/Python-Programming-Internship
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 9 commits
  • 12 files changed
  • 1 contributor

Commits on Jun 20, 2024

  1. Create task1.py

    cherry-420 authored Jun 20, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    gaborbernat Bernát Gábor
    Copy the full SHA
    b627960 View commit details
  2. Create task2.py

    cherry-420 authored Jun 20, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    gaborbernat Bernát Gábor
    Copy the full SHA
    a11a537 View commit details
  3. Create task3.py

    cherry-420 authored Jun 20, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    gaborbernat Bernát Gábor
    Copy the full SHA
    200fabe View commit details
  4. Create task4.py

    cherry-420 authored Jun 20, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    d22f64e View commit details
  5. Add files via upload

    cherry-420 authored Jun 20, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    27c93d5 View commit details
  6. Create TASK1.py

    cherry-420 authored Jun 20, 2024
    Copy the full SHA
    36a7888 View commit details
  7. Create TASK2.py

    cherry-420 authored Jun 20, 2024
    Copy the full SHA
    9b3c721 View commit details
  8. Create TASK3.py

    cherry-420 authored Jun 20, 2024
    Copy the full SHA
    df69520 View commit details
  9. Create TASK4.py

    cherry-420 authored Jun 20, 2024
    Copy the full SHA
    b2991c9 View commit details
Showing with 434 additions and 0 deletions.
  1. +30 −0 TASK-1.py
  2. +59 −0 TASK-2.py
  3. +33 −0 TASK-3.py
  4. +93 −0 TASK-4.py
  5. +30 −0 TASK1.py
  6. +59 −0 TASK2.py
  7. +33 −0 TASK3.py
  8. +93 −0 TASK4.py
  9. +1 −0 task1.py
  10. +1 −0 task2.py
  11. +1 −0 task3.py
  12. +1 −0 task4.py
30 changes: 30 additions & 0 deletions TASK-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#a simple python program to perform basic tasks like addition,subtraction,multiplication,division
print('please select any of the number for performing arithmetic operations')
print("1.Addition")
print('2.Subtraction')
print('3.Multiplication')
print('4.Division')
print('5.exit')
a=int(input('Enter any of the number for performing arithmetic operations'))
def ari(a,var1,var2):
a,var1,var2=a,var1,var2
if(a==1):
print(var1+var2)
if(a==2):
print(var1-var2)
if(a==3):
print(var1*var2)
if(a==4):
print(var1/var2)
return

#Enter Two numbers
if((a>0) and (a<5)):
var1 = int(input('Enter First number: '))
var2 = int(input('Enter Second number: '))
ari(a,var1,var2)
elif(a==5):
exit()
else:
print('Invalid Option')
print('please select 1/2/3/4/5 only')
59 changes: 59 additions & 0 deletions TASK-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
class TaskManager:
def __init__(self):
self.tasks = []

def add_task(self, task):
self.tasks.append({"task": task, "completed": False})

def delete_task(self, index):
if 0 <= index < len(self.tasks):
del self.tasks[index]
else:
print("Invalid task index")

def mark_task_completed(self, index):
if 0 <= index < len(self.tasks):
self.tasks[index]["completed"] = True
else:
print("Invalid task index")

def display_tasks(self):
print("Tasks:")
for i, task in enumerate(self.tasks):
status = "Completed" if task["completed"] else "Pending"
print(f"{i+1}. {task['task']} - {status}")


def main():
task_manager = TaskManager()

while True:
print("\nOptions:")
print("1. Add Task")
print("2. Delete Task")
print("3. Mark Task as Completed")
print("4. View Tasks")
print("5. Exit")

choice = input("Enter your choice: ")

if choice == "1":
task = input("Enter the task: ")
task_manager.add_task(task)
elif choice == "2":
index = int(input("Enter the index of the task to delete: ")) - 1
task_manager.delete_task(index)
elif choice == "3":
index = int(input("Enter the index of the task to mark as completed: ")) - 1
task_manager.mark_task_completed(index)
elif choice == "4":
task_manager.display_tasks()
elif choice == "5":
print("Exiting...")
break
else:
print("Invalid choice. Please try again.")


if __name__ == "__main__":
main()
33 changes: 33 additions & 0 deletions TASK-3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import random

def guess_number():
# Generate a random number between 1 and 100
secret_number = random.randint(1, 100)
attempts = 0
max_attempts = 10

print("Welcome to the Number Guessing Game!")
print("I have chosen a number between 1 and 100. You have", max_attempts, "attempts to guess it.")

while attempts < max_attempts:
try:
guess = int(input("Enter your guess: "))
except ValueError:
print("Invalid input! Please enter a valid number.")
continue

attempts += 1

if guess < secret_number:
print("Too low! Try again.")
elif guess > secret_number:
print("Too high! Try again.")
else:
print("Congratulations! You've guessed the number", secret_number, "correctly in", attempts, "attempts!")
break
else:
print("Sorry, you've run out of attempts. The correct number was", secret_number)

if __name__ == "__main__":
guess_number()

93 changes: 93 additions & 0 deletions TASK-4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import PyPDF2
from PIL import Image
import os


def convert_pdf_to_text(pdf_path, text_output_path):
"""Converts a PDF file to text.
Args:
pdf_path (str): Path to the input PDF file.
text_output_path (str): Path to save the converted text file.
"""
try:
with open(pdf_path, 'rb') as pdf_file:
pdf_reader = PyPDF2.PdfReader(pdf_file)
with open(text_output_path, 'w', encoding='utf-8') as text_file:
# Iterate through each page of the PDF
for page_num in range(len(pdf_reader.pages)):
page = pdf_reader.pages[page_num]
# Extract text from the page and write it to the text file
text_file.write(page.extract_text())
print(f"PDF converted to text successfully. Text file saved at {text_output_path}")
except Exception as e:
print(f"An error occurred: {e}")


def extract_images_from_pdf(pdf_path, image_output_folder):
"""Extracts images from a PDF file.
Args:
pdf_path (str): Path to the input PDF file.
image_output_folder (str): Folder to save the extracted images.
"""
try:
with open(pdf_path, 'rb') as pdf_file:
pdf_reader = PyPDF2.PdfReader(pdf_file)
# Iterate through each page of the PDF
for page_num in range(len(pdf_reader.pages)):
page = pdf_reader.pages[page_num]
xObject = page['/Resources']['/XObject'].getObject()
for obj in xObject:
if xObject[obj]['/Subtype'] == '/Image':
size = (xObject[obj]['/Width'], xObject[obj]['/Height'])
data = xObject[obj]._data
mode = ''
if xObject[obj]['/ColorSpace'] == '/DeviceRGB':
mode = "RGB"
else:
mode = "P"
if xObject[obj]['/Filter'] == '/FlateDecode':
img = Image.frombytes(mode, size, data)
img.save(os.path.join(image_output_folder, f"page{page_num+1}_{obj[1:]}.png"))
elif xObject[obj]['/Filter'] == '/DCTDecode':
img = open(os.path.join(image_output_folder, f"page{page_num+1}_{obj[1:]}.jpg"), "wb")
img.write(data)
img.close()
elif xObject[obj]['/Filter'] == '/JPXDecode':
img = open(os.path.join(image_output_folder, f"page{page_num+1}_{obj[1:]}.jp2"), "wb")
img.write(data)
img.close()
print(f"Images extracted successfully. Saved in {image_output_folder}")
except Exception as e:
print(f"An error occurred: {e}")


def main():
# Get input paths and output folder from user
pdf_path = input("Enter the path to the PDF file: ")
output_folder = input("Enter the output folder path: ")

# Create the output folder if it does not exist
if not os.path.exists(output_folder):
os.makedirs(output_folder)

# Choose conversion option
choice = input("Choose an option:\n1. Convert PDF to text\n2. Extract images from PDF\nEnter your choice: ")

if choice == '1':
# Convert PDF to text
text_output_path = os.path.join(output_folder, "converted_text.txt")
convert_pdf_to_text(pdf_path, text_output_path)
elif choice == '2':
# Extract images from PDF
image_output_folder = os.path.join(output_folder, "extracted_images")
if not os.path.exists(image_output_folder):
os.makedirs(image_output_folder)
extract_images_from_pdf(pdf_path, image_output_folder)
else:
print("Invalid choice. Please choose 1 or 2.")


if __name__ == "__main__":
main()
30 changes: 30 additions & 0 deletions TASK1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#a simple python program to perform basic tasks like addition,subtraction,multiplication,division
print('please select any of the number for performing arithmetic operations')
print("1.Addition")
print('2.Subtraction')
print('3.Multiplication')
print('4.Division')
print('5.exit')
a=int(input('Enter any of the number for performing arithmetic operations'))
def ari(a,var1,var2):
a,var1,var2=a,var1,var2
if(a==1):
print(var1+var2)
if(a==2):
print(var1-var2)
if(a==3):
print(var1*var2)
if(a==4):
print(var1/var2)
return

#Enter Two numbers
if((a>0) and (a<5)):
var1 = int(input('Enter First number: '))
var2 = int(input('Enter Second number: '))
ari(a,var1,var2)
elif(a==5):
exit()
else:
print('Invalid Option')
print('please select 1/2/3/4/5 only')
59 changes: 59 additions & 0 deletions TASK2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
class TaskManager:
def __init__(self):
self.tasks = []

def add_task(self, task):
self.tasks.append({"task": task, "completed": False})

def delete_task(self, index):
if 0 <= index < len(self.tasks):
del self.tasks[index]
else:
print("Invalid task index")

def mark_task_completed(self, index):
if 0 <= index < len(self.tasks):
self.tasks[index]["completed"] = True
else:
print("Invalid task index")

def display_tasks(self):
print("Tasks:")
for i, task in enumerate(self.tasks):
status = "Completed" if task["completed"] else "Pending"
print(f"{i+1}. {task['task']} - {status}")


def main():
task_manager = TaskManager()

while True:
print("\nOptions:")
print("1. Add Task")
print("2. Delete Task")
print("3. Mark Task as Completed")
print("4. View Tasks")
print("5. Exit")

choice = input("Enter your choice: ")

if choice == "1":
task = input("Enter the task: ")
task_manager.add_task(task)
elif choice == "2":
index = int(input("Enter the index of the task to delete: ")) - 1
task_manager.delete_task(index)
elif choice == "3":
index = int(input("Enter the index of the task to mark as completed: ")) - 1
task_manager.mark_task_completed(index)
elif choice == "4":
task_manager.display_tasks()
elif choice == "5":
print("Exiting...")
break
else:
print("Invalid choice. Please try again.")


if __name__ == "__main__":
main()
33 changes: 33 additions & 0 deletions TASK3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import random

def guess_number():
# Generate a random number between 1 and 100
secret_number = random.randint(1, 100)
attempts = 0
max_attempts = 10

print("Welcome to the Number Guessing Game!")
print("I have chosen a number between 1 and 100. You have", max_attempts, "attempts to guess it.")

while attempts < max_attempts:
try:
guess = int(input("Enter your guess: "))
except ValueError:
print("Invalid input! Please enter a valid number.")
continue

attempts += 1

if guess < secret_number:
print("Too low! Try again.")
elif guess > secret_number:
print("Too high! Try again.")
else:
print("Congratulations! You've guessed the number", secret_number, "correctly in", attempts, "attempts!")
break
else:
print("Sorry, you've run out of attempts. The correct number was", secret_number)

if __name__ == "__main__":
guess_number()

Loading