Python帮助显示字符串

时间:2016-10-06 21:42:42

标签: python

def main():
    name = input("Enter your name, eg Zelle: ")
    name = name.lower()
    output = []
    for character in name:
        number = ord(character) - 96
        output.append(number)

    print(output)


main()

这是我到目前为止所做的,但我需要让这个程序运行名称中的每个字母,显示输出如下:

Enter a name (eg, Zelle): Zelle
Letter Z value is 26
Letter e value is 5
Letter l value is 12
Letter l value is 12
Letter e value is 5
The numeric value of the name 'Zelle' is 60

说实话,我不确定该怎么做

3 个答案:

答案 0 :(得分:0)

你去:

def main():
    name = input("Enter your name, eg Zelle: ")
    name = name.lower()
    output = []
    name_value = 0
    for character in name:
        number = ord(character) - 96
        output.append((character,number))
        print("Letter {} value is {}".format(character, number))
        name_value += number
    print("The numeric value of the name: {} is {}".format(name, name_value))

main()

编辑:)

答案 1 :(得分:0)

context.AppUsers.Attach(new AppUser { Id = 1 });
context.AppUsers.Attach(new AppUser { Id = 1 });

这就是我现在所拥有的,非常感谢大家。

答案 2 :(得分:0)

def main():
    name = input("Enter your name, eg Zelle:").lower()
    char_values = [ord(char) for char in name]
    total = sum(char_values)
    for value in char_values:
        print("Letter {} value is {}".format(chr(value), value))
    print("The numeric value of the name {} is {}".format(name, total))

main()