Random words; rather than random number

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
JulieMeier
Posts: 2
Joined: Sat Dec 11, 2021 4:03 pm

Random words; rather than random number

Post by JulieMeier » Sat Dec 11, 2021 4:45 pm

Am actually a total noob and therefore it is good if you feel the need to prefix with the disclaimer.
I can see in the libraries, we have randoms that can generate random numbers, but for me I wanted to have jus t a single button that can do the printing of a Yes or a No. which is the best and easy wat that we should use to solve this?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Random words; rather than random number

Post by pythoncoder » Sat Dec 11, 2021 6:17 pm

Code: Select all

import random
a = ['Yes', 'No']
for _ in range(10):
    print(a[random.getrandbits(1)])
outcome:

Code: Select all

Yes
Yes
No
Yes
Yes
No
No
No
Yes
No
Peter Hinch
Index to my micropython libraries.

Post Reply