Using the random.choice function

I’m using Thinkful.com to learn more about coding in Python, so I’ll be putting in some quick tech tips for coding here and there! Luckily with Thinkful you get a live mentor to help you when you get stuck, which for me seems like a lot. Anyway, I was stuck on a small thing that I’ve actually used before, which is the random.choice() function. Basically the random.choice() lets you put a list into the function and then it will randomly choose one of the items. So, I could have:

v1 = random.choice(“a”, “b”, “c”)

And my v1 variable will end up being either a, b, or c depending on what the function chooses. Easy enough.

So, when I went to provide two lists to my random.choice() function I kept getting an error that it was expecting less arguments than I was giving it. Well, this is simply because the random.choice function will only take one argument (whether that’s a list or other data type). Once I started using two random.choice funcitons for my two lists (one list for each function) everything worked fine.

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top