Show a test score as a fraction and as a percentage.
What to build
One line built with a percentage format code.
Requirements
- Read the number correct and the total.
- Print
Score: C/T (P), where P is the percentage with one decimal and a percent sign.
Input
Two lines, each with one whole number.
Output
One line, as in the example.
Constraints
The total is from 1 to 1000, and the number correct is from 0 to the total.
Example
Input:
7
10
Output:
Score: 7/10 (70.0%)
Why it works
The % format code multiplies by 100 and adds the sign for you, so you only have to give it the fraction.
Examples
Example 1 · Input
7 10
Expected output
Score: 7/10 (70.0%)
Example 2 · Input
2 3
Expected output
Score: 2/3 (66.7%)
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Work out the fraction correct / total.
Hint 2
:.1% turns a fraction into a percentage with one decimal.
Solution
Show one correct solution (try it yourself first)
correct = int(input())
total = int(input())
print(f"Score: {correct}/{total} ({correct / total:.1%})")