Probability of a dice sum

Two fair six-sided dice are rolled. Print the probability that their sum is S, as a fraction in lowest terms (for example 1/6). If the sum is impossible, print 0.

Input

One whole number S.

Output

The probability, like 5/36, or 0.

Examples

Example 1 · Input
7
Expected output
1/6
Example 2 · Input
2
Expected output
1/36

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

Count the pairs (a, b) with a + b equal to the target: 36 pairs in all.

Hint 2

fractions.Fraction(count, 36) reduces the fraction for you.

Hint 3

Print 0 when no pair works.

Solution

Show one correct solution (try it yourself first)
from fractions import Fraction
s = int(input())
count = sum(1 for a in range(1, 7) for b in range(1, 7) if a + b == s)
p = Fraction(count, 36)
print(0 if count == 0 else f"{p.numerator}/{p.denominator}")

Lesson: Outcomes and probability →