abh - HTMLify profile

abh's Profile Picture

abh

501 Files

101798 Views

Latest files of /abh/def

TESTS/ abh/def/TESTS/
9 Items
  • __init__.py
  • func.py
  • are_anagrams.py
  • TESTS.py
  • is_even.py
  • is_isogram.py
  • is_consonant.py
  • is_perfect_square.py
  • is_odd.py abh/def/is_odd.py
    709 Views
    0 Comments
    def is_odd(n: int) -> bool:
    if n == 1:
    return True
    if n == 0:
    return False
    return is_odd(n-2)

    def is_odd(n: int) -> bool:
    median.py abh/def/median.py
    332 Views
    0 Comments
    def median(series):
    s = series.copy()
    s.sort()
    n = len(s)
    if n % 2 == 1:
    return s[n // 2]
    return (s[n//2]+s[(n//2)-1])/2

    len.py abh/def/len.py
    338 Views
    0 Comments
    def len(obj) -> int:
    c = 0
    while obj:
    c += 1
    obj = obj[1:]
    return c

    def len(obj) -> int:
    roman_to_int.py abh/def/roman_to_int.py
    303 Views
    0 Comments
    def roman_to_int(s):
    romans = {'I': 1,
    'V': 5,'X': 10,
    'L': 50, 'C': 100,
    'D': 500, 'M': 1000}
    result = 0
    prev_value = 0
    for c in s[::-1]:
    is_even.py abh/def/is_even.py
    378 Views
    0 Comments
    def is_even(n: int) -> bool:
    if n == 1:
    return False
    if n == 0:
    return True
    return is_even(n-2)

    def is_even(n: int) -> bool:
    digital_sum.py abh/def/digital_sum.py
    341 Views
    0 Comments
    def digital_sum(n: int):
    s = 0
    while n:
    s += n % 10
    n //= 10
    return s

    def digital_sum(n: int):
    average.py abh/def/average.py
    375 Views
    0 Comments
    def average(*nums):
    s = 0
    c = 0
    for n in nums:
    s += n
    c += 1
    return s / c

    mean.py abh/def/mean.py
    304 Views
    0 Comments
    def mean(*nums):
    s = 0
    c = 0
    for n in nums:
    s += n
    c += 1
    return s / c

    is_happy.py abh/def/is_happy.py
    292 Views
    0 Comments
    def is_happy(n: int):
    n = str(n)
    while len(n) != 1:
    s = 0
    for d in n:
    s += int(d)*int(d)
    n = str(s)
    return n in "17"
    README.md abh/def/README.md
    781 Views
    0 Comments
    # ABHDEF
    This is a series of function which I started through my instagram account [@abh.py](https://www.instagram.com/abh.py) all the function of that series you can find in this repositry.
    All the functions are written in python, and tested too but still if you find any bug or you have a better approch for the function then feel free to open an issue.

    ## Hope You like my functions ;)

    ## Functions currently in ABHDEF

    lower.py abh/def/lower.py
    338 Views
    0 Comments
    def lower(s: str) -> str:
    u = "QWERTYUIOPASDFGHJKLZXCVBNM"
    l = "qwertyuiopasdfghjklzxcvbnm"
    for c in s:
    if c in u:
    s = s.replace(c, l[u.find(c)])
    return s

    is_valid_email.py abh/def/is_valid_email.py
    330 Views
    0 Comments
    def is_valid_email(email):
    parts = email.split("@")
    if len(parts) == 2:
    username, domain = parts
    if username and domain:
    if "." in domain:
    return True
    return False
    is_armstrong.py abh/def/is_armstrong.py
    330 Views
    0 Comments
    def is_armstrong(n: int):
    n = str(n)
    p = len(n)
    s = 0
    for d in n:
    s += int(d)**p
    return int(n) == s

    is_palindrome.py abh/def/is_palindrome.py
    298 Views
    0 Comments
    #Check the given string, number or list is palindrome or not.

    def is_palindrome(n: int) -> bool:
    r = 0
    t = n
    while n > 0:
    r = r * 10 + n % 10
    n //= 10
    is_leap_year.py abh/def/is_leap_year.py
    320 Views
    0 Comments
    def is_leap_year(year):
    if not year % 100:
    return not year % 400
    return not year % 4

    mode.py abh/def/mode.py
    386 Views
    0 Comments
    def mode(numbers):
    if not numbers:
    return []
    mode = []
    max_count = 0
    for num in numbers:
    count = numbers.count(num)
    if count > max_count:
    factorial.py abh/def/factorial.py
    318 Views
    0 Comments
    #Calculate the factorial of given number

    def factorial(n: int) -> int:
    if n == 0:
    return 1
    return factorial(n-1) * n

    def factorial(n: int) -> int:
    sum.py abh/def/sum.py
    862 Views
    2 Comments
    def sum(*nums):
    s = 0
    for i in nums:
    s += i
    return s

    def sum(*nums: int):
    s = 0
    sqrt.py abh/def/sqrt.py
    343 Views
    0 Comments
    def sqrt(n):
    return n ** 0.5

    def sqrt(n):
    return n ** (1/2)

    def sqrt(n :int):
    i = 0
    lcm.py abh/def/lcm.py
    397 Views
    0 Comments
    def lcm(a: int, b: int) -> int:
    max = a if a > b else b
    while True:
    if not (max % a and max % b):
    return max
    max += 1

    def lcm(a: int, b: int, max=None):
    pow.py abh/def/pow.py
    338 Views
    0 Comments
    def pow(x, y: int):
    p = 1
    while y:
    p *= x
    y -= 1
    return p

    def pow(x, y):
    upper.py abh/def/upper.py
    466 Views
    0 Comments
    def upper(s: str) -> str:
    u = "QWERTYUIOPASDFGHJKLZXCVBNM"
    l = "qwertyuiopasdfghjklzxcvbnm"
    for c in s:
    if c in l:
    s = s.replace(c, u[l.find(c)])
    return s

    bmi.py abh/def/bmi.py
    344 Views
    0 Comments
    def bmi(weight: "kg", height: "m"):
    return weight / height ** 2

    whr.py abh/def/whr.py
    324 Views
    0 Comments
    def whr(waist: "cm", hip: "cm"):
    return waist / hip

    cbrt.py abh/def/cbrt.py
    403 Views
    0 Comments
    def cbrt(n):
    return n ** (1/3)

    npr.py abh/def/npr.py
    433 Views
    0 Comments
    def npr(n, r):
    return factorial(n) // factorial(n-r)

    def npr(n, r):
    result = 1
    for i in range(r):
    result *= n - i
    return result
    gcd.py abh/def/gcd.py
    352 Views
    0 Comments
    def gcd(a, b):
    if b == 0:
    return a
    return gcd(b, a % b)

    def gcd(a, b):
    while b:
    a, b = b, a % b
    ncr.py abh/def/ncr.py
    333 Views
    0 Comments
    def ncr(n, r):
    numerator = 1
    denominator = 1
    for i in range(r):
    numerator *= n - i
    denominator *= i + 1
    return numerator // denominator

    encrypt_rot13.py abh/def/encrypt_rot13.py
    334 Views
    0 Comments
    def encrypt_rot13(text):
    cipher = ""
    for char in text:
    if char.isalpha():
    offset = 65 if char.isupper() else 97
    cipher += chr((ord(char) - offset + 13) % 26 + offset)
    else:
    cipher += char
    encrypt_caesar_cipher.py abh/def/encrypt_caesar_cipher.py
    366 Views
    0 Comments
    def encrypt_caesar_cipher(text, shift):
    cipher = ""
    for char in text:
    if char.isalpha():
    offset = 65 if char.isupper() else 97
    cipher += chr((ord(char) - offset + shift) % 26 + offset)
    else:
    cipher += char
    encrypt_xor_cipher.py abh/def/encrypt_xor_cipher.py
    312 Views
    0 Comments
    def encrypt_xor_cipher(text, key):
    cipher = ""
    for char in text:
    cipher += chr(ord(char) ^ key)
    return cipher

    char_frequency.py abh/def/char_frequency.py
    281 Views
    0 Comments
    def char_frequency(string):
    freq = {}
    for c in string:
    freq[c] = freq.get(c,0)+1
    return freq

    word_frequency.py abh/def/word_frequency.py
    280 Views
    0 Comments
    def word_frequency(text: str) -> dict:
    words = text.split()
    word_f = {}
    for word in words:
    w = word.strip(".,!?").lower()
    word_f[w] = word_f.get(w,0)+1
    return word_f

    are_anagrams.py abh/def/are_anagrams.py
    401 Views
    0 Comments
    def are_anagrams(s1, s2):
    if len(s1) != len(s2):
    return False
    for c in s1:
    if s1.count(c) != s2.count(c):
    return False
    return True

    is_pangram.py abh/def/is_pangram.py
    283 Views
    0 Comments
    def is_pangram(text):
    letters = "abcdefghijklmnopqrstuvwxyz"
    for char in text:
    if not char.lower() in letters:
    return False
    return True

    def is_pangram(text):
    is_isogram.py abh/def/is_isogram.py
    341 Views
    0 Comments
    def is_isogram(s):
    s = s.lower()
    for c in s:
    if s.count(c) > 1:
    return False
    return True

    def is_isogram(s):
    is_vowel.py abh/def/is_vowel.py
    327 Views
    0 Comments
    def is_vowel(char):
    vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
    return char in vowels

    def is_vowel(char):
    vowels = ["a", "e", "i", "o", "u"]
    return char.lower() in vowels

    is_consonant.py abh/def/is_consonant.py
    259 Views
    0 Comments
    def is_consonant(char):
    consonants = [
    "b", "c", "d", "f", "g", "h",
    "j", "k", "l", "m", "n", "p",
    "q", "r", "s", "t", "v", "w",
    "x", "y", "z", "B", "C", "D",
    "F", "G", "H", "J", "K", "L",
    "M", "N", "P", "Q", "R", "S",
    is_prime.py abh/def/is_prime.py
    267 Views
    0 Comments
    def is_prime(n):
    if n < 2:
    return False
    devisors = 0
    for i in range(1, n+1):
    if n % i == 0:
    devisors += 1
    return devisors < 3
    triangle_number.py abh/def/triangle_number.py
    277 Views
    0 Comments
    def triangle_number(n):
    t = 0
    for i in range(1, n+1):
    t += i
    return t

    def triangle_number(n):
    return sum(range(1, n+1))
    is_perfect_square.py abh/def/is_perfect_square.py
    302 Views
    0 Comments
    def is_perfect_square(n):
    sqrt = int(n ** 0.5)
    return sqrt * sqrt == n

    divisors.py abh/def/divisors.py
    290 Views
    0 Comments
    def divisors(n: int):
    ds = []
    for i in range(1, n+1):
    if not n % i:
    ds.append(i)
    return ds

    def divisors(n: int):
    is_divisible_by.py abh/def/is_divisible_by.py
    726 Views
    0 Comments
    def is_divisible_by(num, div):
    return num % div != 0

    def is_divisible_by(num, div):
    return num / div == 0