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 fillt(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 fillt(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 fillt(list): Array to fill (modified in place)
afficher_t(n, t)
Displays array elements with their indices.
- Parameters:
n(int): Number of elements to displayt(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 displayn(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 inn(int): Number of elements to checkx: 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 forch(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 forx(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 integerb(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 numberb(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
- saisir_f function: Missing
.strip()in the validation loop - Matrix functions: Use NumPy-style indexing, ensure NumPy is installed
- Search functions: Could be optimized with early return for better performance
Requirements
- Python 3.x
- NumPy (for matrix operations)
Installation
- Save the functions to a Python file (e.g.,
utils.py) - Install NumPy if using matrix functions:
pip install numpy - Import the functions you need:
from utils import saisir_n, afficher_t
Contributing
Feel free to submit issues and enhancement requests. When contributing:
- Follow the existing code style
- Add appropriate documentation
- Test your changes thoroughly
- Consider adding English translations for broader accessibility
Changelog for my-library
Version 0.0.1 - 2025-09-11
-First 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bac_info-0.0.1.tar.gz.
File metadata
- Download URL: bac_info-0.0.1.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5fceb81886a1bd958e2845d226010293e958b77b9a26e3e7a1049d89d823830
|
|
| MD5 |
03b7f70c70cd187ffe7be844c8b910c8
|
|
| BLAKE2b-256 |
d8a20dd7b577a8188e867806440e681feb7473f7812f45a32c161be07b7fd225
|
File details
Details for the file bac_info-0.0.1-py3-none-any.whl.
File metadata
- Download URL: bac_info-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd8c0e117706a5c9280fcb72c529ed753e85413aa7b181263c6a6de0d93a880b
|
|
| MD5 |
f344570d709e27d665034f5655c42cf4
|
|
| BLAKE2b-256 |
6c316be2a1b69bb42507c8fa4c37ad1edb0e010e7a17468d99dc669deadb2977
|