Problem 177594 · easy · Phase 01 Prerequisites & Setup

Dice Game with a Reset

loops · lists · accumulation · conditionals

In a simple dice game you add each roll to your score, but whenever you roll a 1 your score drops back to 0 (the 1 itself is not added). Given the list rolls in the order they happened, write pig_score(rolls) that returns the final score.

Examples

Input:  rolls = [3, 4, 1, 5, 2]
Output: 7
Explanation: 3, 7, reset to 0, 5, 7

Input:  rolls = [1]
Output: 0

Constraints

  • 0 <= len(rolls) <= 10**5
  • every roll is an integer from 1 to 6

Goals

  • Loop over a list of values
  • Combine a running total with a reset rule
Starting Python…