Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12']
python-version: ['3.11', '3.12','3.13','3.14']
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -29,7 +29,7 @@ jobs:
- name: Install all dependencies and tools
run: |
python -m pip install --upgrade pip
pip install ruff bandit mypy pytest codespell requests-mock colorama
pip install ruff bandit mypy pytest codespell requests-mock colorama -v

- name: Run Codespell check
run: codespell --skip "*.json,*.txt,*.pdf,*.md" || true
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*~
.DS_Store
Thumbs.db

.python-version
# Python
__pycache__/
*.pyc
Expand All @@ -32,7 +32,7 @@ wheels/
*.egg-info/
.installed.cfg
*.egg

.ruff_cache/*
# Testing
.pytest_cache/
.coverage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

## Find bright students and weak students

from dotenv import load_dotenv
import os

from dotenv import load_dotenv

base = os.path.dirname(__file__)
load_dotenv(os.path.join(base, ".env"))
student_record = os.getenv("STUDENTS_RECORD_FILE")

import pickle
import logging

# Define logger with info
# import polar
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# binary file to search a given record

import pickle
from dotenv import load_dotenv


def search():
Expand Down
3 changes: 2 additions & 1 deletion 1 File handle/File handle binary/update2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Updating records in a binary file
# ! Have a .env file please
import pickle
import os
import pickle

from dotenv import load_dotenv

base = os.path.dirname(__file__)
Expand Down
3 changes: 2 additions & 1 deletion 1 File handle/File handle text/question 5.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Write a function in python to count the number of lowercase
alphabets present in a text file “happy.txt"""

import time
import os
import time

from counter import Counter

print(
Expand Down
1 change: 0 additions & 1 deletion 1-file_handle
Submodule 1-file_handle deleted from c9283c
3 changes: 1 addition & 2 deletions 8_puzzle.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from queue import PriorityQueue
from typing import List, Tuple, Optional, Set
from typing import List, Optional, Set, Tuple


class PuzzleState:
Expand Down Expand Up @@ -39,7 +39,6 @@ def manhattan(self) -> int:
distance += abs(x - i) + abs(y - j)
return distance


def is_goal(self) -> bool:
"""Check if current state matches goal."""
return self.board == self.goal
Expand Down
2 changes: 1 addition & 1 deletion A solution to project euler problem 3.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def solution(n: int = 600851475143) -> int:
"""
try:
n = int(n)
except (TypeError, ValueError):
except TypeError, ValueError:
raise TypeError("Parameter n must be int or passive of cast to int.")
if n <= 0:
raise ValueError("Parameter n must be greater or equal to one.")
Expand Down
20 changes: 10 additions & 10 deletions AREA OF TRIANGLE.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
def get_valid_side(prompt:str):
while True:
try:
value = float(input(prompt))
if value <=0:
print("Side must be positive")
continue
return value
except ValueError:
print("Invalid Input")
def get_valid_side(prompt: str):
while True:
try:
value = float(input(prompt))
if value <= 0:
print("Side must be positive")
continue
return value
except ValueError:
print("Invalid Input")


a = get_valid_side("Enter side 1: ")
Expand Down
199 changes: 145 additions & 54 deletions Add_two_Linked_List.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,159 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Add two numbers represented as linked lists.

Each linked list stores digits in reverse order (head is the least significant digit).
This allows straightforward addition with carry propagation.

Example:
Number 946 is stored as 6 -> 4 -> 9
Number 22 is stored as 2 -> 2
Sum 968 is stored as 8 -> 6 -> 9
"""

from typing import Optional


class Node:
def __init__(self, data):
self.data = data
self.next = None
"""Singly linked list node."""

def __init__(self, data: int) -> None:
self.data: int = data
self.next: Optional["Node"] = None


class LinkedList:
def __init__(self):
self.head = None
"""A singly linked list with head pointing to the least significant digit."""

def __init__(self) -> None:
self.head: Optional[Node] = None

def insert_at_beginning(self, new_data):
new_node = Node(new_data)
def append(self, data: int) -> None:
"""
Append a new node with `data` at the end (tail).
This keeps the head as the least significant digit.
"""
new_node = Node(data)
if self.head is None:
self.head = new_node
return
new_node.next = self.head
self.head = new_node

def add_two_no(self, first, second):
prev = None
temp = None
carry = 0
while first is not None or second is not None:
first_data = 0 if first is None else first.data
second_data = 0 if second is None else second.data
Sum = carry + first_data + second_data
carry = 1 if Sum >= 10 else 0
Sum = Sum if Sum < 10 else Sum % 10
temp = Node(Sum)
if self.head is None:
self.head = temp
else:
prev.next = temp
prev = temp
if first is not None:
first = first.next
if second is not None:
second = second.next
if carry > 0:
temp.next = Node(carry)

def __str__(self):
temp = self.head
while temp:
print(temp.data, "->", end=" ")
temp = temp.next
return "None"
curr = self.head
while curr.next is not None:
curr = curr.next
curr.next = new_node

@classmethod
def from_number(cls, num: int) -> "LinkedList":
"""
Create a linked list representing the digits of `num`
with head as the least significant digit.

>>> lst = LinkedList.from_number(946)
>>> lst.head.data
6
>>> lst.head.next.data
4
>>> lst.head.next.next.data
9
"""
lst = cls()
if num == 0:
lst.append(0)
return lst
while num > 0:
lst.append(num % 10)
num //= 10
return lst

def to_number(self) -> int:
"""
Convert the linked list back to an integer.

>>> LinkedList.from_number(946).to_number()
946
"""
result = 0
multiplier = 1
curr = self.head
while curr is not None:
result += curr.data * multiplier
multiplier *= 10
curr = curr.next
return result

def __str__(self) -> str:
"""Display the linked list from head (least significant) to tail."""
parts = []
curr = self.head
while curr is not None:
parts.append(str(curr.data))
curr = curr.next
return " -> ".join(parts) if parts else "Empty"

def __repr__(self) -> str:
return f"LinkedList({self})"

if __name__ == "__main__":
first = LinkedList()
second = LinkedList()
first.insert_at_beginning(6)
first.insert_at_beginning(4)
first.insert_at_beginning(9)

second.insert_at_beginning(2)
second.insert_at_beginning(2)
def add_two_numbers(l1: LinkedList, l2: LinkedList) -> LinkedList:
"""
Add two numbers represented by linked lists (head = least significant digit).

print("First Linked List: ")
print(first)
print("Second Linked List: ")
print(second)
Returns a new LinkedList representing the sum.

Examples:
>>> l1 = LinkedList.from_number(946)
>>> l2 = LinkedList.from_number(22)
>>> result = add_two_numbers(l1, l2)
>>> result.to_number()
968
>>> str(result)
'8 -> 6 -> 9'
"""
dummy = Node(0) # Sentinel node
tail = dummy
carry = 0
p = l1.head
q = l2.head

while p is not None or q is not None or carry:
val1 = p.data if p else 0
val2 = q.data if q else 0
total = val1 + val2 + carry
carry = total // 10
digit = total % 10

tail.next = Node(digit)
tail = tail.next

if p:
p = p.next
if q:
q = q.next

result = LinkedList()
result.add_two_no(first.head, second.head)
print("Final Result: ")
print(result)
result.head = dummy.next
return result


if __name__ == "__main__":
# Demonstration
first = LinkedList.from_number(946)
second = LinkedList.from_number(22)

print("First Linked List (head = least significant):")
print(first) # 6 -> 4 -> 9

print("Second Linked List:")
print(second) # 2 -> 2

result = add_two_numbers(first, second)
print("Sum (head = least significant):")
print(result) # 8 -> 6 -> 9

print(f"Sum as integer: {result.to_number()}") # 968

# Run doctests
import doctest

doctest.testmod(verbose=True)
1 change: 1 addition & 0 deletions Anonymous_TextApp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import tkinter as tk

from PIL import Image, ImageTk
from twilio.rest import Client

Expand Down
5 changes: 3 additions & 2 deletions Armstrong_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ def is_armstrong_number(number: str) -> bool:
"""Check if a number (as a string) is a narcissistic/Armstrong number."""
# Logic: Get the exponent (number of digits)
exponent = len(number)

# Logic: Sum each digit raised to the power in a single line
# This uses a generator, which is memory efficient.
total = sum(int(digit) ** exponent for digit in number)

# Return the boolean result instead of printing
return total == int(number)


# --- Main execution ---
user_input = input("Enter the number: ")

Expand Down
5 changes: 3 additions & 2 deletions Audio_Summarizer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import whisper
import os
import re

import openai
import os
import whisper


def transcript_generator():
Expand Down
2 changes: 1 addition & 1 deletion AutoComplete_App/backend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sqlite3
import json
import sqlite3


class AutoComplete:
Expand Down
1 change: 1 addition & 0 deletions AutoComplete_App/frontend.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from tkinter import *

import backend


Expand Down
Loading
Loading