Return a seven-segment display string of number. The returned string will be padded with zeros if it is smaller than minWidth.
(number, minWidth=0)
| 16 | |
| 17 | |
| 18 | def getSevSegStr(number, minWidth=0): |
| 19 | """Return a seven-segment display string of number. The returned |
| 20 | string will be padded with zeros if it is smaller than minWidth.""" |
| 21 | |
| 22 | # Convert number to string in case it's an int or float: |
| 23 | number = str(number).zfill(minWidth) |
| 24 | |
| 25 | rows = ['', '', ''] |
| 26 | for i, numeral in enumerate(number): |
| 27 | if numeral == '.': # Render the decimal point. |
| 28 | rows[0] += ' ' |
| 29 | rows[1] += ' ' |
| 30 | rows[2] += '.' |
| 31 | continue # Skip the space in between digits. |
| 32 | elif numeral == '-': # Render the negative sign: |
| 33 | rows[0] += ' ' |
| 34 | rows[1] += ' __ ' |
| 35 | rows[2] += ' ' |
| 36 | elif numeral == '0': # Render the 0. |
| 37 | rows[0] += ' __ ' |
| 38 | rows[1] += '| |' |
| 39 | rows[2] += '|__|' |
| 40 | elif numeral == '1': # Render the 1. |
| 41 | rows[0] += ' ' |
| 42 | rows[1] += ' |' |
| 43 | rows[2] += ' |' |
| 44 | elif numeral == '2': # Render the 2. |
| 45 | rows[0] += ' __ ' |
| 46 | rows[1] += ' __|' |
| 47 | rows[2] += '|__ ' |
| 48 | elif numeral == '3': # Render the 3. |
| 49 | rows[0] += ' __ ' |
| 50 | rows[1] += ' __|' |
| 51 | rows[2] += ' __|' |
| 52 | elif numeral == '4': # Render the 4. |
| 53 | rows[0] += ' ' |
| 54 | rows[1] += '|__|' |
| 55 | rows[2] += ' |' |
| 56 | elif numeral == '5': # Render the 5. |
| 57 | rows[0] += ' __ ' |
| 58 | rows[1] += '|__ ' |
| 59 | rows[2] += ' __|' |
| 60 | elif numeral == '6': # Render the 6. |
| 61 | rows[0] += ' __ ' |
| 62 | rows[1] += '|__ ' |
| 63 | rows[2] += '|__|' |
| 64 | elif numeral == '7': # Render the 7. |
| 65 | rows[0] += ' __ ' |
| 66 | rows[1] += ' |' |
| 67 | rows[2] += ' |' |
| 68 | elif numeral == '8': # Render the 8. |
| 69 | rows[0] += ' __ ' |
| 70 | rows[1] += '|__|' |
| 71 | rows[2] += '|__|' |
| 72 | elif numeral == '9': # Render the 9. |
| 73 | rows[0] += ' __ ' |
| 74 | rows[1] += '|__|' |
| 75 | rows[2] += ' __|' |
nothing calls this directly
no outgoing calls
no test coverage detected