Skip to the content

The percentage you got right

Problem

A quiz has total questions and you answered right of them correctly. Return what percentage you got right, rounded to one decimal: 7 out of 10 gives you 70.0, and 2 out of 3 gives you 66.7.

If the quiz has no questions at all (total is 0), return 0.0 instead of dividing.

Examples

  • 7, 10 → 70

  • 3, 4 → 75

  • With decimals

    2, 3 → 66.7

  • A perfect quiz

    20, 20 → 100

Besides these, the challenge has hidden tests that are revealed when you submit your solution.

You start with this

Python

def percent_right(right, total):
    pass

JavaScript

function percentRight(right, total) {
}
Solve this challenge

It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.

More O(1) challenges

See all challenges →