Created
February 22, 2021 00:46
-
-
Save leveled/bc52f68bfab6e81473e8d9f84bb50ef1 to your computer and use it in GitHub Desktop.
Capture an unlimited number of positional arguments given to a function in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import randint | |
def roll(*dice): | |
return sum(randint(1, die) for die in dice) | |
>>> roll(20) | |
18 | |
>>> roll(6, 6) | |
9 | |
>>> roll(6, 6, 6) | |
8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment