Learn to code with step-by-step lessons. A place for students to work through programming fundamentals and build skills.
One possible program:
import random
battery = 100
hours = 0
while battery > 0:
drain = random.randint(5, 15)
battery -= drain
hours += 1
print("After hour", hours, "battery ~", max(battery, 0))
print("Battery dead after", hours, "hours.")