nithilan 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nithilan/__init__.py +4 -0
- nithilan/core.py +51 -0
- nithilan-0.1.0.dist-info/METADATA +34 -0
- nithilan-0.1.0.dist-info/RECORD +6 -0
- nithilan-0.1.0.dist-info/WHEEL +5 -0
- nithilan-0.1.0.dist-info/top_level.txt +1 -0
nithilan/__init__.py
ADDED
nithilan/core.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import math
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def factorial(x: float) -> int | float:
|
|
7
|
+
if x < 0:
|
|
8
|
+
raise ValueError("factorial is not defined for negative numbers")
|
|
9
|
+
if x % 1 == 0:
|
|
10
|
+
count = int(x)
|
|
11
|
+
result = 1
|
|
12
|
+
while count > 0:
|
|
13
|
+
result *= count
|
|
14
|
+
count -= 1
|
|
15
|
+
return result
|
|
16
|
+
return math.gamma(x + 1)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def ask(prompt: str) -> bool | None:
|
|
20
|
+
print(prompt + " (y/n): ", end="", flush=True)
|
|
21
|
+
|
|
22
|
+
if sys.platform == "win32":
|
|
23
|
+
import msvcrt
|
|
24
|
+
|
|
25
|
+
char = msvcrt.getch().decode("utf-8", errors="ignore")
|
|
26
|
+
else:
|
|
27
|
+
import termios
|
|
28
|
+
import tty
|
|
29
|
+
|
|
30
|
+
try:
|
|
31
|
+
file_descriptor = sys.stdin.fileno()
|
|
32
|
+
previous_settings = termios.tcgetattr(file_descriptor)
|
|
33
|
+
try:
|
|
34
|
+
tty.setraw(file_descriptor)
|
|
35
|
+
char = sys.stdin.read(1)
|
|
36
|
+
finally:
|
|
37
|
+
termios.tcsetattr(
|
|
38
|
+
file_descriptor,
|
|
39
|
+
termios.TCSADRAIN,
|
|
40
|
+
previous_settings,
|
|
41
|
+
)
|
|
42
|
+
except (io.UnsupportedOperation, OSError):
|
|
43
|
+
char = input()
|
|
44
|
+
|
|
45
|
+
char = char.lower()
|
|
46
|
+
if char == "y":
|
|
47
|
+
return True
|
|
48
|
+
if char == "n":
|
|
49
|
+
return False
|
|
50
|
+
print("Incorrect argument")
|
|
51
|
+
return None
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nithilan
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Small Python utilities for everyday programs
|
|
5
|
+
Author: Nithilan Vivek
|
|
6
|
+
Project-URL: Homepage, https://nithi.land
|
|
7
|
+
Keywords: utilities,factorial,terminal
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# nithilan
|
|
14
|
+
|
|
15
|
+
`nithilan` is a small collection of Python utilities for everyday programs.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
python -m pip install nithilan
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from nithilan import ask, factorial
|
|
27
|
+
|
|
28
|
+
print(factorial(5))
|
|
29
|
+
|
|
30
|
+
if ask("Continue?"):
|
|
31
|
+
print("Continuing")
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`factorial` supports non-negative integers and real values supported by the gamma function. `ask` reads a single `y` or `n` response from an interactive Windows, macOS, or Linux terminal.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
nithilan/__init__.py,sha256=DwXx5EUs8LuCYC15dBtwz-RTJsGBFjPg8fvC-hgyVF8,87
|
|
2
|
+
nithilan/core.py,sha256=PLEb8VZQBKE7syIb0VPyDVJuYC5kwEtcOQOy1MQvFo8,1265
|
|
3
|
+
nithilan-0.1.0.dist-info/METADATA,sha256=cD6IIhEkCPiI_QLyrG2KZX8WbWmnOnG93kZFd4BTNl0,836
|
|
4
|
+
nithilan-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
5
|
+
nithilan-0.1.0.dist-info/top_level.txt,sha256=wJQi31o_FcPmH1BauPopIM__LTZ6YyMP2sFFY0by3_E,9
|
|
6
|
+
nithilan-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
nithilan
|