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!