3 of 4
Build a poll creator for your Discord server! Users give a question and options, and your bot formats a beautiful poll message.
Write two functions that work together to create formatted polls.
format_option(index, text)["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣"]format_option(0, "Pizza") → "1️⃣ Pizza"create_poll(question, options)format_option() for each optionThe poll should look like:
📊 POLL: What should we play?
━━━━━━━━━━━━━━━━━━━━
1️⃣ Minecraft
2️⃣ Roblox
3️⃣ Fortnite
Vote by reacting below!
EMOJIS = ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣"] def format_option(index, text): # Return the emoji + text for one option pass def create_poll(question, options): # Build the full poll string # Start with the header, add each formatted option, end with footer pass # Test your functions: print(format_option(0, "Pizza")) # Output: 1️⃣ Pizza print(format_option(2, "Sushi")) # Output: 3️⃣ Sushi print("---") poll1 = create_poll("What should we play?", ["Minecraft", "Roblox", "Fortnite"]) print(poll1) print("===") poll2 = create_poll("Best programming language?", ["Python", "JavaScript", "C++", "Scratch"]) print(poll2)
1️⃣ Pizza
3️⃣ Sushi
---
📊 POLL: What should we play?
━━━━━━━━━━━━━━━━━━━━
1️⃣ Minecraft
2️⃣ Roblox
3️⃣ Fortnite
Vote by reacting below!
===
📊 POLL: Best programming language?
━━━━━━━━━━━━━━━━━━━━
1️⃣ Python
2️⃣ JavaScript
3️⃣ C++
4️⃣ Scratch
Vote by reacting below!
Use the EMOJIS list with the index:
def format_option(index, text): return f"{EMOJIS[index]} {text}"
Build the string piece by piece. You can use \n for new lines:
result = f"📊 POLL: {question}\n" result += "━━━━━━━━━━━━━━━━━━━━\n" # Add each option... result += "\nVote by reacting below!"
Use enumerate() or range(len(...)) to get both the index and the item:
for i, option in enumerate(options): result += format_option(i, option) + "\n"
EMOJIS = ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣"] def format_option(index, text): return f"{EMOJIS[index]} {text}" def create_poll(question, options): result = f"📊 POLL: {question}\n" result += "━━━━━━━━━━━━━━━━━━━━\n" for i, option in enumerate(options): result += format_option(i, option) + "\n" result += "\nVote by reacting below!" return result
create_poll calls format_option+= and \nWrite your code below. Click Run to test locally, then click Send to Discord to have the bot post your output to the server!