Simple Python program to create numeric values based on Unicode values, would like tips to streamline my code -


print("this program calculate numeric value of name given input.")  name = input("please enter full name: ") name_list = name.split(' ') name_list2 = [] x in name_list:     y = list(x)     x in y:         name_list2.append(x)  print(name_list2) num_value = 0  x in name_list2:     y = ord(x)     print("the numeric value of", x, "is", y)     num_value = num_value + y  print("the numeric value of name is: ", num_value) 

any tips on how simplify appreciated, knowledge couldn't see easier way split list, split out each character (to avoid adding in whitespace value of 32), , add them up.

you can iterate on name , sum ord's of each character excluding spaces count if not ch.isspace():

name = input("please enter full name: ") print("the numeric value of name is: ", sum(ord(ch) ch in name if not ch.isspace())) 

if want see each letter use loop:

name = input("please enter full name: ") sm = 0 ch in name:     if not ch.isspace():         y = ord(ch)         print("the numeric value of", ch, "is", y)         sm += y print("the numeric value of name is: ", sm) 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -