Skip to main content

Command Palette

Search for a command to run...

Implement a picker wheel in Python 3 using random

A very simple implementation in Python 3 using the random module

Updated
1 min read
D

Intégrateur d'applications web open source expérimenté avec plus de 5 ans d'expertise le suivi d'intégration d'applications web Python 3 containerisées, assistance technique et résolution de problèmes, suivi et intégration de développements et tests. Initialement axé sur le support client et la résolution de problèmes, j'ai développé des compétences en suivi et réalisation d'intégrations techniques et développements en rapport avec la maintenance, le suivi, la mise à jour de la pile applicative, ou les exigences ou problèmes remontés par le client. Je recherche de nouvelles opportunités pour mettre à profit mes compétences techniques et interpersonnelles dans un environnement stimulant.

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:

  1. We import the random module, which provides functionality for generating random numbers and making random choices.

  2. We define a function picker_wheel that takes a list of choices and returns a random choice from that list. It uses the random.choice function to do this.

  3. We define a list of beer types.

  4. We use the picker_wheel function to select a random beer type.

  5. We print out the selected beer.