generate a random t-shirt size from xs to xl for my stpry in python

To generate a random t-shirt size from XS to XL in Python, you can use the random.choice() function from the random library to randomly select a size from a list or tuple of available sizes.

Here's an example code snippet that generates a random t-shirt size:

main.py
import random

sizes = ['XS', 'S', 'M', 'L', 'XL']  # list of available sizes
random_size = random.choice(sizes)  # randomly select a size from the list

print(f"The random t-shirt size is {random_size}.")
206 chars
7 lines

In the above code, we first define a list of available sizes. Then, we use the random.choice() function to randomly select a size from this list. Finally, we print the randomly selected size using an f-string.

You can modify the sizes list to include any additional sizes you may need.

related categories

gistlibby LogSnag