The percentage you got right
- O(1) · Trivial
- Free
- Python
- JavaScript
- operations
- division
- decimals
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):
passJavaScript
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.