Skip to content

Commit

Permalink
version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
thenithinbalaji committed Mar 19, 2022
1 parent 326e075 commit 281ba27
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 34 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ switch(number_of_switches)

**Required:** Lower & Upper Limits `<int>`
**Default:** Lower Limit = 0
**Return Type:** `<tuple>`
**Return Type:** `<int>`
```
spinner(lowerLimit, upperLimit)
```
Expand All @@ -98,8 +98,9 @@ spinner(lowerLimit, upperLimit)
**Default:** Number of Toys = 0
<br>
**If you want to use a combination of toys then,**
**Required:** List of toys as `<list>`,`<tuple>`
**Required:** names of toys as ``<tuple>, <list>, <str>``
```
combi("coin", "switch")
combi(("switch", "cat", "dice"))
combi(["dreidel", "coin", "coin", "cat"])
```
Expand Down
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Spinner:

+ **Required:** Lower & Upper Limits ``<int>``
+ **Default:** Lower Limit = 0
+ **Return Type:** ``<tuple>``
+ **Return Type:** ``<int>``

::

Expand All @@ -82,10 +82,11 @@ Toy Combinations:
+ **Return Type:** ``<tuple>``

**If you want to use a combination of toys then,**
**Required:** List of toys as ``<list>``,\ ``<tuple>``
**Required:** names of toys as ``<tuple>, <list>, <str>``

::

combi("coin", "switch")
combi(("switch", "cat", "dice"))
combi(["dreidel", "coin", "coin", "cat"])

Expand Down
81 changes: 51 additions & 30 deletions pyrandtoys/functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import random as rop
from typing import Tuple
from typing import Union


def dice(count: int = 1) -> Tuple[int, ...]:
Expand Down Expand Up @@ -114,7 +115,7 @@ def spinner(lower: int, upper: int = 0) -> int:
Returns:
int: The value at which the spinner has stopped spinning.
Result is a number between lower and upper.
"""
if lower > upper:
Expand Down Expand Up @@ -161,53 +162,73 @@ def card(count: int = 1) -> Tuple[str, ...]:
return res


def combi(list: list = []) -> Tuple[str, ...]:
def combi(*argv: Union[str, int, list, tuple]) -> Tuple[Union[int, str], ...]:
"""
Randomise combinations between other functions
Parameters:
list (list) : The list of functions to randomise
Functions to randomise
Returns:
tuple: The values of the randomised functions
"""
res = ()

if isinstance(list, str):
list = [list]
res = []

elif isinstance(list, int):
temp = []
sample_space = ["coin", "dice", "switch", "card"]
for item in argv:
if isinstance(item, str):
item = item.lower()
try:
res.append(eval(item + "()")[0])
except:
res.append(None)

for _ in range(list):
rand_op = rop.choice(sample_space)
temp.append(rand_op)
elif isinstance(item, list) or isinstance(item, tuple):
temp = ()
for i in item:

list = temp
if isinstance(i, str):
i = i.lower()
try:
temp += (eval(i + "()")[0],)
except:
temp += (None,)

for obj in list:
obj = obj.lower()
elif isinstance(i, int):
sample_space = ["coin", "dice", "switch", "card"]
temp2 = ()

if obj == "coin":
res += coin()
for _ in range(i):
rand_op = rop.choice(sample_space)
try:
temp2 += (eval(rand_op + "()")[0],)
except:
temp2 += (None,)

elif obj == "dice":
res += dice()
temp += (temp2,)

elif obj == "dreidel":
res += dreidel()
else:
temp += (None,)

elif obj == "cat":
res += cat()
res.append(temp)

elif obj == "switch":
res += switch()
elif isinstance(item, int):

elif obj == "card":
res += card()
sample_space = ["coin", "dice", "switch", "card"]
temp = ()

else:
res += (None,)
for _ in range(item):
rand_op = rop.choice(sample_space)
try:
temp += (eval(rand_op + "()")[0],)
except:
temp += (None,)

return res
res.append(temp)

res = tuple(res)

if len(res) == 1 and isinstance(res[0], tuple):
return res[0]
else:
return res

0 comments on commit 281ba27

Please sign in to comment.