Compute an NPS Score

Easy ⏱ 8 min 86% acceptance ★★★★★ 4.6
Write nps(ratings) from 0-10 survey ratings: promoters rate 9-10, detractors 0-6, passives 7-8. NPS = %promoters − %detractors, rounded to the nearest integer. Empty input returns 0.

Examples

Example 1
Input
nps([10, 9, 8, 6, 2])
Output
0
Explanation

40% promoters − 40% detractors.

Constraints

  • Percentages of ALL responses.
  • Round the final score.

Topics

Business Logicsurvey metrics

Companies

QualtricsSurveyMonkeyZoho

Hints

Hint 1

Count with comprehensions or a loop.

Hint 2

The passive band affects the denominators only.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.