Implement a picker wheel in Python 3 using random
A very simple implementation in Python 3 using the random module
Discovering the diverse universe of craft beers can be both an exciting and overwhelming journey. But how do you choose which beer style to try next?
Enter: the Craft-Beer Picker Wheel.
import random
def picker_wheel(choices):
"""Select a random choice from a list."""
choice = random.choice(choices)
return choice
beer_types = [
"Bières IPA (India Pale Ale)",
"Bières Stout",
"Bières Sour Ale",
"Bières Saison/Farmhouse Ale",
"Bières Porte",
"Bières Lager",
"Bières Pilsner",
"Bières de Blé (Wheat Beers)",
]
selected_beer = picker_wheel(beer_types)
print("The picker wheel selected:", selected_beer)
Usage and result
user@computer % python3 craft_beer_picker_wheel.py
The picker wheel selected: Bières Sour Ale
In this script:
We import the
random
module, which provides functionality for generating random numbers and making random choices.We define a function
picker_wheel
that takes a list of choices and returns a random choice from that list. It uses therandom.choice
function to do this.We define a list of beer types.
We use the
picker_wheel
function to select a random beer type.We print out the selected beer.