Python calculate many different sum in for loop -
i trying calculate letter value (a = 1, b = 2...z = 26) of input. other characters considered 0 code listed below:
alpha = list('abcdefjhijklmnopqrstuvwxyz') = [] sum1= 0 while true: b = input() if b == '': break else: a.append(b.lower()) lst_len = len(a) in range(lst_len): elem_len = len(a[i]) j in range(elem_len): if (a[i][j]) in alpha: num = alpha.index(a[i][j]) + 1 sum1 += num else: pass print sum1
my question how print sum value of each in loop instead of keep adding previous sums
thank you!
move sum1 = 0
after for in range(lst_len):
, gets reset after every time inner loop finishes.
Comments
Post a Comment