Chapter 3 · Quest 4 of 5 · 10 XP
Dice Goblin
🎲 A dice goblin lives in every board game. Your bot can roll dice with Python's random module: random.randint(1, 6) gives a whole number from 1 to 6, both ends included.
import random coin = random.randint(1, 2) print(coin)
2
Your output will be different each time: that's random. The checker rolls your dice hundreds of times to make sure every side can come up, and nothing else.
Instructions
- Make
roll(sides)that returnsrandom.randint(1, sides). - Make
tools = {"roll": roll}and storejson.loads(pip.ask_with_tools("Roll a 20 sided dice", tools))inchoice. - Run the tool Pip picked and print the number you rolled.
💡 Hint
Add import random at the top. Running the tool works like last quest: tools[choice["tool"]](**choice["args"]). Wrap it in print().
bot.py
Terminal