A seven-segment display shows a digit by switching on some of seven bars, called a, b, c, d, e, f and g. A decoder turns a 4-bit digit into the seven control bits.
What to build
Print the segment pattern for each digit you are given.
Requirements
- The segments are in the order a, b, c, d, e, f, g, written as seven bits (1 = on).
- Digit 0 is
1111110, 1 is0110000, 2 is1101101, 3 is1111001, 4 is0110011, 5 is1011011, 6 is1011111, 7 is1110000, 8 is1111111and 9 is1111011. - A digit above 9 (the codes 10 to 15) is not a decimal digit: print
0000000(all off).
Input
The first line has the number of queries q. Then q lines, each with a number from 0 to 15.
Output
One line for each query: the seven bits.
Constraints
1 ≤ q ≤ 16.
Example
Input:
3
0
1
8
Output:
1111110
0110000
1111111
Why it works
A decoder is a truth table with 4 inputs and 7 outputs, and each output column is one Boolean function of the four bits (one for each segment). Reading it as rows, as here, gives all seven functions at once. The codes 10 to 15 never appear in decimal, so a designer treats them as don't-cares and can make the circuit smaller.
Examples
3 0 1 8
1111110 0110000 1111111
4 2 3 4 5
1101101 1111001 0110011 1011011
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Make a table with one 7-character string for each digit, in the order of segments a, b, c, d, e, f, g.
Hint 2
The table is in the Requirements section. Copy it exactly.
Hint 3
Read one digit per query and print the string of its row.
Solution
Show one correct solution (try it yourself first)
q = int(input())
table = ["1111110", "0110000", "1101101", "1111001", "0110011", "1011011", "1011111", "1110000", "1111111", "1111011"]
for _ in range(q):
n = int(input())
print(table[n] if n <= 9 else "0000000")
▶ Open this solution in the compiler, then press Visualize to watch it run step by step