Had a go at some code golf today, went for this challenge: http://codegolf.stackexchange.com/questions/5382/create-an-ascii-progress-bar
Here is my solution which is 125 characters small.
1 2 3 4 5 6 7 |
a,b=raw_input().split() a=int(a) b=float(b) c=int(a*b) d="|"*c+" "*(a-c) e=len(d)/2 print"["+d[:e]+`int(b*100)`+"%"+d[e:]+"]" |
So the output for this would be as such:
1 2 3 4 5 6 7 8 9 |
jack@Icarus:~/Projects/code golf$ python progress_bar.py 10 0.7 [|||||70%|| ] jack@Icarus:~/Projects/code golf$ python progress_bar.py 10 0.56 [|||||56% ] jack@Icarus:~/Projects/code golf$ python progress_bar.py 10 0.8 [|||||80%||| ] |
Questions? Comments?