Wheel of Names with Python

Zaneta Gilda
3 min readAug 21, 2023

Wheel of Names is a digital wheel spinner to pick a name randomly. It adds a sense of excitement in order to make a decision. It can decide what to eat, what to eat, and who is the winner randomly. User has to input several names as many as the user needs. Then, the user clicks to spin the wheel. Here’s what it looks like when Wheel of Names has selected the name randomly.

In this article, the writer will show how to create a simple “Wheel of Names” using Python and how it can be used in various events. The following is the code for the wheel of names in Python.

  1. This is what it looks like when you run the first Python syntax. User has to enter several names and the names have to be separated by commas. The writer uses definition wheel_of_names(), input, and .split(‘,’) to separate each name. If the user inputs a number or anything other than letters, there will be an output stating that no names have been entered, and the program will restart. In this article, the writer inputs four names (Keira, Theodore, James, Serena) as an example. Once it’s done, the writer will press “enter”.
import random

def wheel_of_names():
print("Welcome to the Wheel of Names!")
listname = input("Enter a list of names separated by commas: ")
names = listname.split(',')

2. Then, Python will randomly select one of those names and print the sentence “Spinning the wheel…” as if Python is spinning the Wheel of Names. Once Python has made a random selection, the chosen name will be displayed with the following sentence. The user can spin the wheel again to choose from the remaining names. The selected winner’s name will no longer be used by using names.remove(winner).

  while names:
print("Spinning the wheel...\n")
winner = random.choice(names)
print("The winner is:", winner)
names.remove(winner)

3. The user can print “yes”,“YES”, “NO”, “no” to continue or end this Wheel of Names. The writer has used .lower() to ensure that all user inputs can be read by Python and the process can be run smoothly.

        play_again = input("Do you want to spin the wheel again? (yes/no): ")
if play_again.lower() != "yes": #.lower agar case insensitive
print("Exiting the game.")
break

4. Last, this condition if has purpose which is to make all those codes run automatically and smoothly in sequence with each other.

if __name__ == "__main__":
wheel_of_names()

The Wheel of Names has many benefits to your daily life. The Wheel of Names with Python offers you a great way to create a simple yet entertaining touch to your projects or events. By harnessing the use of Python, readers are able to sharpen their Python skills and make something entertaining to the readers’ events.

--

--