I am having a hard time figuring out what I am doing wrong. I am in grad school and have to take an intro to programming class, yay me, and its python. Learning some decent stuff but more frustrated than i have EVER been in my life!
Please see example of what I am supposed to do and what I have so far:
>>> compress( '11111' )
'10000101'
so I am supposed to define a "compress" command that takes any strings of 1/0 and "compresses". The first bit in the block of 8 represents the digit, and the rest of the 7 represent the quantity of times that digit appears in binary....hence the answer.
this is what I have so far:
def compress (s):
if len (s) ==0: return 0
f=s[0]
i=0
while i < len (s):
if s[i] != f:
return i
i+=1 #gives us how many of the first number appear in the string
print f,binaryof (i)
but 2 issues. Its not represented in block of 8 and there is a space I cant seem to get rid of.
Please help, thanks in advance!
This post has been edited by kapitalist: 15 October 2010 - 06:54 PM

New Topic/Question
Reply




MultiQuote





|