Skip to main content

A collection of utility functions for common programming tasks including input validation, array/matrix operations, string processing, and mathematical calculations.

Project description

Python Utility Functions Library

A collection of utility functions for common programming tasks including input validation, array/matrix operations, string processing, and mathematical calculations.

Overview

This library provides a set of utility functions designed to help with:

  • Safe user input validation and collection
  • Array and matrix manipulation
  • String and character operations
  • Mathematical computations
  • Data structure searches

Functions Reference

Input Validation Functions

saisir_n(bi, bs)

Prompts the user to input an integer within a specified range.

  • Parameters:
    • bi (int): Lower bound (inclusive)
    • bs (int): Upper bound (inclusive)
  • Returns: Valid integer within the range [bi, bs]
  • Usage: number = saisir_n(1, 100) # Get integer between 1 and 100

saisir_f(bi, bs)

Prompts the user to input a float within a specified range.

  • Parameters:
    • bi (float): Lower bound (inclusive)
    • bs (float): Upper bound (inclusive)
  • Returns: Valid float within the range [bi, bs]
  • Usage: decimal = saisir_f(0.0, 10.0) # Get float between 0.0 and 10.0

saisir_ch()

Prompts the user to input a string containing only alphabetic characters.

  • Returns: Valid alphabetic string (whitespace stripped)
  • Usage: name = saisir_ch() # Get alphabetic string

Array Operations

remplir_t(n, t)

Fills an array with integer values from user input.

  • Parameters:
    • n (int): Number of elements to fill
    • t (list): Array to fill (modified in place)

remplir_t_f(n, t)

Fills an array with float values from user input.

  • Parameters:
    • n (int): Number of elements to fill
    • t (list): Array to fill (modified in place)

remplir_t_ch(n, t)

Fills an array with string values from user input.

  • Parameters:
    • n (int): Number of elements to fill
    • t (list): Array to fill (modified in place)

afficher_t(n, t)

Displays array elements with their indices.

  • Parameters:
    • n (int): Number of elements to display
    • t (list): Array/list to display

Matrix Operations

remplir_m(m, n)

Fills a square matrix with integer values from user input.

  • Parameters:
    • m (2D array): Matrix to fill (modified in place)
    • n (int): Size of the square matrix (n x n)

remplir_m_f(m, n)

Fills a square matrix with float values from user input.

  • Parameters:
    • m (2D array): Matrix to fill (modified in place)
    • n (int): Size of the square matrix (n x n)

remplir_m_ch(m, n)

Fills a square matrix with string values from user input.

  • Parameters:
    • m (numpy.ndarray): Matrix to fill (modified in place)
    • n (int): Size of the square matrix (n x n)

afficher_m(m, n)

Displays a square matrix with indices.

  • Parameters:
    • m (2D array): Matrix to display
    • n (int): Size of the square matrix (n x n)

Search Functions

existance_t(t, n, x)

Checks if a value exists in an array.

  • Parameters:
    • t (list): Array to search in
    • n (int): Number of elements to check
    • x: Value to search for
  • Returns: True if value exists, False otherwise

existance_ch(c, ch)

Checks if a character exists in a string.

  • Parameters:
    • c (str): Character to search for
    • ch (str): String to search in
  • Returns: True if character exists, False otherwise

existance_int(c, x)

Checks if a digit exists in an integer.

  • Parameters:
    • c (int): Digit to search for
    • x (int): Integer to search in
  • Returns: True if digit exists, False otherwise

Mathematical Functions

pgcd(a, b)

Calculates the Greatest Common Divisor (PGCD) using the Euclidean algorithm.

  • Parameters:
    • a (int): First integer
    • b (int): Second integer
  • Returns: Greatest Common Divisor of a and b

puissance(a, b)

Calculates a raised to the power of b using iterative multiplication.

  • Parameters:
    • a (int/float): Base number
    • b (int): Exponent
  • Returns: Result of a^b
  • Note: Handles negative exponents and zero cases

sommechiffre(ch)

Calculates the sum of all digits in a string representation of a number.

  • Parameters:
    • ch (str): String containing digits
  • Returns: Sum of all digits

String Processing Functions

palindrom(ch)

Checks if a string is a palindrome.

  • Parameters:
    • ch (str): String to check
  • Returns: True if string is a palindrome, False otherwise

Usage Examples

# Input validation example
age = saisir_n(0, 150)  # Get age between 0 and 150
height = saisir_f(0.0, 3.0)  # Get height between 0.0 and 3.0 meters
name = saisir_ch()  # Get alphabetic name

# Array operations example
import numpy as np
arr = [0] * 5
remplir_t(5, arr)  # Fill array with user input
afficher_t(5, arr)  # Display the array

# Matrix operations example
matrix = np.zeros((3, 3), dtype=int)
remplir_m(matrix, 3)  # Fill 3x3 matrix
afficher_m(matrix, 3)  # Display the matrix

# Search examples
found = existance_t([1, 2, 3, 4, 5], 5, 3)  # Returns True
char_exists = existance_ch('a', "hello")  # Returns False
digit_exists = existance_int(5, 12345)  # Returns True

# Mathematical operations
gcd_result = pgcd(48, 18)  # Returns 6
power_result = puissance(2, 8)  # Returns 256
digit_sum = sommechiffre("12345")  # Returns 15

# String processing
is_palindrome = palindrom("racecar")  # Returns True

Known Issues

  1. saisir_f function: Missing .strip() in the validation loop
  2. Matrix functions: Use NumPy-style indexing, ensure NumPy is installed
  3. Search functions: Could be optimized with early return for better performance

Requirements

  • Python 3.x
  • NumPy (for matrix operations)

Installation

  1. Save the functions to a Python file (e.g., utils.py)
  2. Install NumPy if using matrix functions: pip install numpy
  3. Import the functions you need: from utils import saisir_n, afficher_t

Contributing

Feel free to submit issues and enhancement requests. When contributing:

  1. Follow the existing code style
  2. Add appropriate documentation
  3. Test your changes thoroughly
  4. Consider adding English translations for broader accessibility

Changelog for my-library

Version 0.0.3 - 2025-09-13

-Second Realease

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bac_info-0.0.3.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bac_info-0.0.3-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file bac_info-0.0.3.tar.gz.

File metadata

  • Download URL: bac_info-0.0.3.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.4

File hashes

Hashes for bac_info-0.0.3.tar.gz
Algorithm Hash digest
SHA256 09af084082f5bcc9beb299e7c5691b395cc0ca407f6aa6d4ec538b49982ebcfd
MD5 1cd2fd3dca5f25e1456c632e1c1053e6
BLAKE2b-256 9101dc1e33d0c9c282ce9a4257a0ee0d96ab3dcb09b3f0272071fc31ea7263e0

See more details on using hashes here.

File details

Details for the file bac_info-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: bac_info-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.4

File hashes

Hashes for bac_info-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3cd3ef8d34d233fbb69b7ddb358c08d0c9487fff891448126a74c760e9d45c0a
MD5 de1a853fc4acedc29b77828c6d377a8b
BLAKE2b-256 b1f6370eba47eb58ef6f4a31a42e669dca0192ce22f1a7e56fb36d14ebfc567f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page