To generate a random t-shirt size from XS to XL, you can use the random module in Python. Here's an example using lists and the choice function:
main.py224 chars11 lines
In this code, we create a list of t-shirt sizes from XS to XL. The random.choice()
function randomly selects a size from that list, so the output will be a single size. Additionally, if you want to generate size with equal probability, you can use random.choices()
function instead of random.choice()
function.
main.py247 chars11 lines
In this example, we use random.choices()
function instead of random.choice()
. The k
parameter is used to specify how many random sizes you want to generate in this example we generates a list of 10
sizes.
Additionally, you can add conditional operators to generate the sizes of medium or above.
main.py244 chars11 lines
In this code, we slice the list to exclude sizes smaller than medium, so random.choice()
will only generate sizes M, L, and XL.
gistlibby LogSnag