Build a Random Decision Maker
Build a Python CLI app that randomly picks from options you type in.
Introduction
30 Second Summary
Everyone gets stuck choosing between options sometimes. Where to eat, which movie to watch, which task to tackle first.
In this project, you will build a command-line Decision Maker app in Python that picks a random option from any list you give it.
What You'll Build
Type in options like "pizza, sushi, tacos" and get an instant random pick you can run whenever you are stuck on a decision.
By the end of this project, you'll have:
- A Decision Maker script that accepts any options you type and picks one at random in under a second.
- Built-in input validation that catches empty or single-option input and tells you exactly what went wrong.
- A looping interface that lets you make decision after decision without restarting the script.
- Secret Mission: Add weighted choices so you can make some options more likely than others.
Before We Start
Before you dive into code, let's lock in what you're about to build and why it matters to you. Think of a real decision you've been stuck on recently.
Set Up Your Project
Your Decision Maker will be a Python script you run directly in the terminal. Before writing any code, you need to confirm that Python actually works on your machine.
You also need a dedicated folder and file to keep your code organized. This step handles all of that so you are ready to start building.
In this step, get ready to:
- Confirm Python 3.14.6 runs in VS Code's terminal.
- Create a decision-maker project folder on your Desktop.
- Set up an empty decision_maker.py file to write your code in.
Confirm Python is working
You need a terminal inside VS Code to run Python commands. The terminal is a text-based panel where you type commands and see their output.
- In VS Code, click Terminal in the top menu bar.
- Click New Terminal.
A terminal panel opens at the bottom of VS Code.
- Verify Python is installed by running this command:
python --version
You should see Python 3.14.6 printed in the terminal.
Don't see Python 3.14.6?
If you see 'python' is not recognized, Python may not be on your system PATH. Reinstall Python from python.org and make sure to check the box that says Add Python to PATH during installation.
If you see an older version, you need to install Python 3.14.6 from python.org and restart VS Code after installation.
help me fix my Python installation
Create your project folder
Every project needs its own folder to keep files organized. You will create a folder called decision-maker on your Desktop so it is easy to find.
- Move to your Desktop by running this command:
cd ~/Desktop
- Create your project folder and move into it by running these commands:
mkdir decision-maker
cd decision-maker
- Confirm you are inside the new folder by running:
cd
You should see a path ending in decision-maker printed in the terminal. This confirms you are in the right place.
Seeing an error on mkdir?
If you see a message that the folder already exists, that means you created it previously. Just run cd decision-maker to move into the existing folder and continue.
help me navigate to my project folder
Create your Python file
Now you need an empty Python file to write your code in. This file is where your Decision Maker app will live.
- Create the file by running this command:
type nul > decision_maker.py
- Confirm the file was created by running:
dir
You should see decision_maker.py listed in the output.
Prefer the GUI?
You can also create the file from VS Code's menu. Click File in the top menu bar, then New File. Save it as decision_maker.py inside your decision-maker folder.
- Open the file in the editor by running:
code decision_maker.py
The file opens in a new tab in VS Code. It is completely empty, which is expected.
File not opening in VS Code?
If code is not recognized, click File in VS Code's top menu, then Open File, and navigate to your decision-maker folder on the Desktop to open decision_maker.py manually.
help me open my Python file in VS Code
Your environment is ready. Next up, you will write your first lines of Python and watch the app pick a random option from a list.
Pick from a Hardcoded List
Your environment is confirmed and decision_maker.py is open in your editor. Time to write some actual code.
Before dealing with user input, you need to prove that Python can pick a random item from a list. This step gives you a working picker in under 5 lines of code.
In this step, get ready to:
- Write a random picker using Python's random module.
- Run the script multiple times to confirm random selection works.
Write a random picker with a hardcoded list
The random module is part of Python's standard library. It gives you tools for generating random values without installing anything extra.
- In decision_maker.py, paste the following code to create your random picker:
import random
options = ["pizza", "sushi", "tacos"]
result = random.choice(options)
print(f"I choose: {result}")
What does this code do?
- import random loads Python's built-in module for generating random values. No install required.
- options is a list holding three food choices. A list is an ordered collection wrapped in square brackets.
- random.choice(options) picks one item from the list at random and stores it in result.
- The f"..." syntax is an f-string. It lets you embed variables directly inside a string using curly braces.
- Save decision_maker.py by pressing Ctrl+S.
- Run the script by entering this command in your terminal:
python decision_maker.py
You should see something like I choose: sushi printed in your terminal. The specific option varies each time.
Seeing an error instead?
- If you see SyntaxError, check that your f-string has both an opening and closing double quote, and that curly braces surround result.
- If you see ModuleNotFoundError, double-check the spelling. It should be import random with a lowercase r.
- Make sure you saved the file before running the command. Unsaved changes won't be picked up by Python.
Help me debug my decision_maker.py script
Confirm the randomness by running it multiple times
One successful run proves the script works. Multiple runs prove the randomness.
What do you think will happen if you run the exact same script three times in a row? Will it always pick the same option, or different ones each time?
- Run the script two more times by pressing the up arrow in your terminal and hitting Enter each time.
You should see a different option appear at least once across your three runs (e.g., I choose: pizza then I choose: tacos). Occasionally the same option repeats. That is normal for random selection.
✔️ Awesome, I've got everything!
Great. Make sure you've saved decision_maker.py before moving on.
ⓧ I'd like to double check the full code
Here is the complete decision_maker.py at this point:
import random
options = ["pizza", "sushi", "tacos"]
result = random.choice(options)
print(f"I choose: {result}")
Your picker works. Next up, you'll replace that hardcoded list with real user input so the app can handle any decision you throw at it.
Accept User Input
Your random picker works, but it only ever chooses between pizza, sushi, and tacos. A hardcoded list solves one decision forever.
You need the app to accept whatever options you type in so it is actually useful. In this step, you'll replace the fixed list with Python's input() function so the script asks for your choices every time you run it.
In this step, get ready to:
- Replace the hardcoded list with live user input using input() and .split(",").
- Test the app by typing your own comma-separated options.
- Discover what happens when you enter bad input.
Replace the hardcoded list with user input
Python's input() function pauses the script and waits for you to type something. Combined with .split(","), it can turn a single string of comma-separated words into a list of options.
- Replace the entire contents of decision_maker.py with this code:
import random
# Display a header so the user knows what app they're running
print("--- Decision Maker ---")
user_input = input("Enter your options separated by commas: ")
# Split the input on commas and strip whitespace from each option
options = [option.strip() for option in user_input.split(",")]
# Pick a random option and display the result
result = random.choice(options)
print(f"\nI choose: {result}")
What does this code do?
- input("Enter your options separated by commas: ") pauses the script and waits for you to type. Whatever you enter becomes the string stored in user_input.
- .split(",") breaks that string into a list wherever it finds a comma.
- option.strip() removes extra spaces around each option, so " sushi " becomes "sushi".
- random.choice(options) picks one item at random from the resulting list.
- Save decision_maker.py.
✔️ Awesome, I've got everything!
Great. Double check you've saved your file before running it.
ⓧ I'd like to double check the full code
import random
print("--- Decision Maker ---")
user_input = input("Enter your options separated by commas: ")
options = [option.strip() for option in user_input.split(",")]
result = random.choice(options)
print(f"\nI choose: {result}")
Run the script with your own options
What do you think will happen when you run the script now? Will it immediately pick an option, or will something different happen first?
- Run the script by entering this command in your terminal:
python decision_maker.py
- When you see the prompt, type beach, mountains, city and press Enter.
The script pauses and waits for your input. After you type your options, it picks one at random and prints something like I choose: mountains.
- Run it a few more times with different options to see that it picks randomly each time.
Seeing an error instead of a prompt?
- Check that you saved decision_maker.py after pasting the new code.
- Make sure your terminal is inside the decision-maker folder. Run cd decision-maker if you're not sure.
- Confirm you replaced the entire file contents, not just added to the existing code.
help me fix an error when running decision_maker.py
Discover the input gap
The app works great with normal input. But what do you think happens if you run the script and just press Enter without typing any options?
- Run the script again:
python decision_maker.py
- When prompted, press Enter without typing anything.
The app prints something like I choose: with nothing after it. It picked from a list containing one empty string. The app didn't crash, but it gave you a completely useless result.
- Run it one more time and type a single option with no commas (like just pizza).
It always picks the only option you gave it. The app accepts garbage input and pretends everything is fine.
Why is this a problem?
A decision maker that happily "decides" between zero or one options is not making a real decision. The app needs to check that the user entered at least two real options before picking. That check is called input validation, and you'll add it in the next step.
Your app accepts whatever you type, but it never checks whether the input makes sense. Next up, you'll add validation that rejects bad input before the app ever picks.
Validate the Input
In the last step, you discovered a problem. Your app happily accepts empty input or a single option and produces a meaningless result instead of telling you something went wrong.
Good software does not let bad data slip through. In this step, you will add validation that checks the user entered at least two real options before picking one.
In this step, get ready to:
- Filter empty strings out of the options list.
- Add a check that requires at least 2 valid options before picking.
Add input validation
Right now, when someone presses Enter without typing anything, .split(",") produces a list containing one empty string. Your app treats that empty string as a valid option. You need two things: a filter that removes empty strings, and a length check that catches lists with fewer than 2 options.
- In decision_maker.py, select all the existing code and replace it with this updated version:
import random
print("--- Decision Maker ---")
user_input = input("Enter your options separated by commas: ")
# Split input into a list and strip whitespace from each option
options = [option.strip() for option in user_input.split(",")]
# Remove any empty strings (from extra commas or blank input)
options = [option for option in options if option]
# Only pick if we have at least 2 real options
if len(options) < 2:
print("Please enter at least 2 options separated by commas.")
else:
result = random.choice(options)
print(f"\nI choose: {result}")
What changed from the previous version?
Two new pieces of logic make this version robust:
- options = [option for option in options if option] is a second list comprehension that keeps only non-empty strings. In Python, an empty string "" is "falsy", so if option filters it out.
- if len(options) < 2: checks whether the cleaned list has at least 2 entries. If not, the user gets a clear error message instead of a nonsensical pick.
- Save decision_maker.py.
Seeing a syntax error?
- Make sure the if and else keywords are at the same indentation level (no leading spaces).
- Check that the lines inside if and else are indented with exactly 4 spaces. Mixing tabs and spaces causes Python to reject the file.
Help me fix an indentation error in my Python if/else block.
Test with bad input
Before you run this, think about what you expect to see if you press Enter without typing anything. Will the app crash, show a random pick, or show your error message?
- Run the script by entering this command in the terminal:
python decision_maker.py
- When prompted, press Enter without typing anything.
You should see Please enter at least 2 options separated by commas. printed instead of a nonsensical pick. That is your validation doing its job.
- Run the script again and type a single option with no commas (like pizza). You should see the same error message.
- Run the script one more time and type only commas (like ,,). The filter removes the empty strings, so you get the error message again.
- Finally, run it with valid input like beach, mountains, city. Confirm it still picks one of those options.
Still seeing a random pick with empty input?
- Make sure you have the second list comprehension (options = [option for option in options if option]) on its own line AFTER the first one. Without it, empty strings stay in the list.
- Confirm your if len(options) < 2: check comes after both list comprehensions. If it is placed before the filter, it counts empty strings as valid options.
Help me debug why my validation is not catching empty input.
✔️ Awesome, I've got everything!
Great. Double check you have saved decision_maker.py.
ⓧ I'd like to double check the full code
Here is the complete decision_maker.py at this point:
import random
print("--- Decision Maker ---")
user_input = input("Enter your options separated by commas: ")
options = [option.strip() for option in user_input.split(",")]
options = [option for option in options if option]
if len(options) < 2:
print("Please enter at least 2 options separated by commas.")
else:
result = random.choice(options)
print(f"\nI choose: {result}")
Your app now rejects bad input with a clear message. There is one annoyance left though. Every time you want to make a new decision, you have to re-run the script from scratch. Next up, you will wrap everything in a loop so you can make decisions back-to-back.
Add a Decision Loop
Your app now catches bad input before it causes problems. But every time you want another decision, you have to restart the script from scratch.
In this step, you will wrap your existing logic into a reusable function and add a loop that keeps the app running. You will be able to make decisions back-to-back until you choose to exit.
In this step, get ready to:
- Refactor your existing code into a reusable function.
- Add a while loop so the app keeps running for multiple decisions.
- Test that bad input mid-session does not crash the app.
Wrap the picker logic in a function
Right now your code runs from top to bottom once and exits. To call the same logic repeatedly, you need it inside a function you can invoke on demand.
- Select all the existing code in decision_maker.py and replace it with this:
import random
def get_choice():
# Display the header each time a new decision starts
print("\n--- Decision Maker ---")
user_input = input("Enter your options separated by commas: ")
# Split and clean the input
options = [option.strip() for option in user_input.split(",")]
options = [option for option in options if option]
# Require at least 2 options for a meaningful choice
if len(options) < 2:
print("Please enter at least 2 options separated by commas.")
return
# Pick and display the result
result = random.choice(options)
print(f"\nI choose: {result}")
What does this code do?
You wrapped all the existing logic inside a function called get_choice(). The logic is the same as before, with one key difference.
- Instead of an else branch for the success case, you now use return to exit the function early when validation fails. This removes a level of indentation and makes the happy path clearer.
- Nothing calls get_choice() yet. The next chunk adds the loop that drives it.
Add the main loop and entry point
A while True loop runs forever until something inside it calls break. You will use this pattern to keep prompting the user for new decisions.
- Add the following code below your get_choice() function (after the last line of get_choice):
def main():
# Welcome message shown once at startup
print("Welcome to the Decision Maker!")
print("I'll help you choose between your options.")
# Keep looping until the user wants to stop
while True:
get_choice()
# Ask if they want to go again
play_again = input("\nMake another decision? (yes/no): ").strip().lower()
if play_again != "yes":
print("Goodbye!")
break
# Only run main() when this file is executed directly
if __name__ == "__main__":
main()
What does this code do?
main() prints a welcome message once, then enters a while True loop. Each pass through the loop calls get_choice() and then asks the user if they want to continue.
- .strip().lower() normalises the response so that "YES", " yes ", and "Yes" all count as a yes.
- Anything other than "yes" triggers break, which exits the loop and prints "Goodbye!".
- if __name__ == "__main__": ensures main() only runs when you execute the file directly. If you ever imported this file into another script, the function would not auto-run.
- Save decision_maker.py.
Seeing a syntax error when you save?
- Make sure def main(): starts at the same indentation level as def get_choice(): (column 0, no leading spaces).
- Confirm there is no code left over from the old version sitting outside a function. Everything except import random and the if __name__ line should live inside one of the two functions.
- help me fix a syntax error in my decision maker script
✔️ Awesome, I've got everything!
Great. Make sure you have saved decision_maker.py before moving on.
ⓧ I'd like to double check the full code
Your file should contain these sections in order:
- import random at the very top.
- The get_choice() function (prints header, takes input, splits, filters, validates, picks, prints result).
- The main() function (welcome message, while True loop calling get_choice(), exit prompt with break).
- if __name__ == "__main__": main() at the bottom.
Scroll up and confirm each chunk matches what you pasted.
Test the decision loop
Before you run the script, think about what you expect to happen. Will the app exit after one pick, or will it ask you something new?
- Run the script by entering this command in your terminal:
python decision_maker.py
- When prompted, type pizza, sushi, tacos and press Enter.
- The app picks one option and then asks Make another decision? (yes/no):.
- Type yes and enter another set of options. Repeat once more so you make 2-3 decisions total.
- When you are done, type no at the prompt.
You should see Goodbye! printed and the script exits cleanly back to your terminal prompt.
- Run the script one more time. This time, when asked for options, just press Enter without typing anything.
The app shows your validation message and then asks if you want to make another decision. It does not crash or exit unexpectedly.
App exits immediately or shows a NameError?
- If you see NameError: name 'get_choice' is not defined, make sure def get_choice(): appears above def main(): in the file.
- If nothing prints at all, confirm the last two lines are if __name__ == "__main__": followed by main() (indented).
- help me debug why my decision maker loop is not working
Secret mission
Add Weighted Choices
Not all decisions are created equal. Sometimes you want pizza three times more than sushi. Upgrade your Decision Maker to support weighted choices so some options are more likely to be picked.
Clean Up Your Resources
Clean Up Your Resources
This project runs entirely locally using Python's standard library, so there are no ongoing costs or cloud resources to worry about.
Resources you used:
- The decision-maker project folder on your Desktop (contains decision_maker.py).
Keep everything running
No action needed. Choose this if you want to keep using your Decision Maker or plan to extend it further.
- Your decision-maker folder stays on your Desktop.
- Run it anytime with python decision_maker.py from inside the folder.
Pause - I'll come back to this later
Since this is a local Python script with no running processes, there is nothing to pause. Your file sits quietly on disk until you run it again.
- No background processes to stop.
- No memory or CPU used while the script is not running.
- Come back anytime and run python decision_maker.py to pick up where you left off.
Delete - I don't want to use this again
Remove the project folder entirely to start fresh.
- Close the decision_maker.py file in VS Code if it is still open.
- In the VS Code terminal, move out of the project folder and delete it by running these commands:
cd ..
rmdir /s /q decision-maker
- Confirm the folder is gone by running:
dir
You should no longer see decision-maker in the listing.
Nice Work!
Nice Work!
Nice work! You just built a fully functional Decision Maker app in Python that picks random options from anything you type in.
You've learned how to:
- Built a command-line app that uses Python's random module to pick from any list of options you give it.
- Parsed user input with input(), .split(), and .strip() to handle comma-separated options cleanly.
- Added input validation to reject bad data and a while loop to keep making decisions without restarting the script.
- Secret Mission: Upgraded to weighted random choices using random.choices() with custom weight parsing so some options can appear more often than others.
Ready to quiz yourself?