python - How do you add numbers that are under a for loop? -


     charkey = input('\nwhat 8 character key used in encryption?\n')     in charkey:       c = (ord(i))       print('asc2num',c)       output:       8 character key used in encryption?     (*&^%$     asc2num 40     asc2num 42     asc2num 38     asc2num 94     asc2num 37     asc2num 36  

i need add these numbers together, have tried sum(c), not work.

sum() take list or iterable object argument.

demo:

exception:

in [105]: sum(1) --------------------------------------------------------------------------- typeerror                                 traceback (most recent call last) <ipython-input-105-5771d20eddf7> in <module>() ----> 1 sum(1)  typeerror: 'int' object not iterable 

valid:

in [106]: sum([1,2,3,4,5]) out[106]: 15 

create variable addition:

demo:

in [108]: add = 0  in [109]: in range(5):    .....:     add = add +    .....:       in [110]: add out[110]: 10 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -