# [Tutor] Checksum program

taserian taserian at gmail.com
Wed Mar 23 15:28:25 CET 2011

```On Wed, Mar 23, 2011 at 9:55 AM, Lezlie Kline <lezlie.kline at gmail.com>wrote:

> Tony,
>
> For your question "What's the checksum for a completely empty message
> (i.e., no characters at all)?" Do you mean the value or how do I write it?
> I would think the value would be 0.
>
Correct. Now think of that as your starting point; any message containing
characters is going to start at 0 plus the sum of the ASCII values of each
of its characters. Where would you store the initial value of an empty
message?

> My understanding of where I'm storing the ASCII values for each letter is
> ord(message[i])
>
ord isn't a variable, it's a function. It's calculating the ASCII value of
the i-th character of "message".

> I don't think it's been initialized properly, but that's where I don't
> understand about the accumulator for strings.  I originally thought this for
> the accumulator:
>
> output=""
> for i in range(len(message[i])"
>
>     print"The value of message[i] is ", message[i]
>     output=output+" " + ord(message[i])
>
>     print"The value of the message is ", output
>
> but strings and integers don't concatentate AND my ord(value) isn't
> accumulating AND I thing my output is getting overwritten.
>
You don't want to mix apples and oranges. Your variable "message" contains a
full name in the test case, "John X. Doe", for example, so it's made up of
characters. What should the accumulator contain, if you're going to be

> Here's part of the problem.  The person "teaching" me Python provides some
> information and then jumps to the programs so I'm struggling in the fuzzy
> dark.  I was given the range "for i in range(len(message[i]):print"The value
> of message[i] is ", message[i]"  and I understand that it obtains the length
> of my message, but I don't really understand the [i] part other than [i]
> represents integer and the "i" in for i is the iteration of the loop so when
> you ask the question "message[i] will provide you the character at position
> i. What are you doing with it?" I'm not sure what you're asking?
>
> I'm sorry to be so dense.  Believe it or not I've been working on this
> program for a week....
>
> L.

Is this homework?

Tony R.

>  On Wed, Mar 23, 2011 at 9:30 AM, taserian <taserian at gmail.com> wrote:
>
>>  On Wed, Mar 23, 2011 at 9:09 AM, Lezlie Kline <lezlie.kline at 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.
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110323/49566247/attachment-0001.html>
```