Pack 2 · Challenge 3 of 5 · 10 XP · ⏱ 4 min
Battery Check
🔋 Pip can report its status as JSON. Read one value out of it and show it with a percent sign.
import json
data = json.loads('{"hp": 7}')
print("HP: " + str(data["hp"]))HP: 7
Instructions
- Load
pip.ask("Give me your mood as JSON")into a dict calleddatawithjson.loads. - Print
Battery: 87%usingdata["battery"], not typing 87.
💡 Hint
data = json.loads(pip.ask("Give me your mood as JSON")). Then "Battery: " + str(data["battery"]) + "%".
bot.py
Terminal