On Wed, Mar 23, 2011 at 9:09 AM, Lezlie Kline <lezlie.kl...@gmail.com>wrote:
> Hi, > > I'm trying to work out the bugs in a program for calculating the checksum > (modulo 256) of an input string. I'm testing it with my full name and I'm a > beginner with Python. Here's what I have so far. > > def main(): > print"This program creates a checksum for a message." > name=raw_input("Please enter the message to encode: ") > message=name > output=name > for i in range(len(message)): > print"The value of message[i] is ", message[i] > output=output+name+ord(message[i]) > print"The value of the message is ", output > checksum=(output)%256 > print"The checksum is ", checksum > > main() > I'd like to give you some pointers so you can solve it yourself: What's the checksum for a completely empty message (i.e., no characters at all)? Where are you storing the (ASCII) values of each letter? Has it been initialized properly? > I know I'm offbase somewhere, but I'm not understanding some parts of the > accumulator part of the program. I need it to work with the message[i] > intact. In other words, I need the pseudo code to go something like this: > > print message > get input > find length > using length in range function accumulate ASCII numbers > calculate checksum > print checksum > > I'd appreciate any help offered as I'm "pulling out my hair." message[i] will provide you the character at position i. What are you doing with it? Tony R.
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor