0%
⭐ 0 XPMap
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

  1. Make roll(sides) that returns random.randint(1, sides).
  2. Make tools = {"roll": roll} and store json.loads(pip.ask_with_tools("Roll a 20 sided dice", tools)) in choice.
  3. 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().

Ask the community

bot.py
Terminal
← BackNext →

Chapter 3: Tools

The full quest map

Talk it out

  1. Read the instruction with the ✗ out loud.
  2. Say what your code does, line by line, as if to a friend.
  3. Find the line where what it does and what you want split apart.
  4. Press Run and read the terminal. Is that what you expected?
  5. Still stuck? Press Ask Pip why, or peek at the solution.
  6. Or ask on the community help board: say which quest, and paste your code.
New badge!

Your bot just got a new part. See it on the quest map.

Name your bot

It levels up as you play, and gets a new part with every chapter.