Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
17
Task/Sparkline-in-unicode/Python/sparkline-in-unicode.py
Normal file
17
Task/Sparkline-in-unicode/Python/sparkline-in-unicode.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import re
|
||||
try: raw_input
|
||||
except: raw_input = input
|
||||
|
||||
# Unicode: 9601, 9602, 9603, 9604, 9605, 9606, 9607, 9608
|
||||
try: bar = u'▁▂▃▄▅▆▇█'
|
||||
except: bar = '▁▂▃▄▅▆▇█'
|
||||
barcount = len(bar) - 1
|
||||
while True:
|
||||
line = raw_input('Numbers please separated by space/commas: ')
|
||||
numbers = [float(n) for n in re.split(r'[\s,]+', line.strip())]
|
||||
mn, mx = min(numbers), max(numbers)
|
||||
extent = mx - mn
|
||||
sparkline = ''.join(bar[int( (n - mn) / extent * barcount)]
|
||||
for n in numbers)
|
||||
print('min: %5f; max: %5f' % (mn, mx))
|
||||
print(sparkline)
|
||||
Loading…
Add table
Add a link
Reference in a new issue