[Tutor] Checksum program

taserian taserian at gmail.com
Wed Mar 23 15:54:53 CET 2011


When replying to the Python Tutor list, please use "Reply All" instead of
just "Reply". I meant to put this in my previous message, but it remained in
"meant to" phase and never got implemented properly. 8-)

 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 adding numbers? Numbers
>>
>
Then your code above should look something like this:

output= 0
for i in message:
    print"Character i in message: ", message[i]
    output=output + ord(message[i])
print "The value of the message is ", output


In pseudocode:
Start with the value for an empty message in the variable "output".
For every character in "message":
    Print the character
    Add the ASCII value of the character to the accumulator "output".
After all of the characters have been processed, show the final value of
"output"


>
>> Is this homework? Not anymore  I'm past that and I live in NC and I've
>> been desperately looking for a tutor but I'm having difficulty finding
>> anyone who does Python programming.  They don't teach it at NC State or UNC
>> or Wake Tech.  If you don't want to help.  I understand.  This was my last
>> resort.
>>
>
>>
>
Not at all. It's just that we have a rule about not doing anyone's homework
on the list. It robs them of the learning experience, and can provide a
grade which hasn't been earned properly.

Tony R.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110323/dfc030d6/attachment.html>


More information about the Tutor mailing list