简体   繁体   English

如果我想使用 Python 对结果求和,我该怎么办?

[英]What do i have to do if i want to Sum my result using Python?

import string
dict = {}
bool = False
user_string = input("Bitte gebe hier die Buchstaben ein, welche du Summieren möchtest:")
String_Num = ""

for i, char in enumerate(string.ascii_lowercase):
    dict[i] = char # This is dictinoary.

for val in user_string.lower():
    if(val.isdigit()):
       print("Entschuldige, der Vorgang konnte nicht abgeschlossen werden!")
       bool = True
       break
    for key, value in dict.items():
        if(val == value):
            String_Num += str(key+1)
            # For spaces
            String_Num += " "

if (not bool):
    print(String_Num)

Add just one line after the 'print(String_Num)'在“print(String_Num)”之后仅添加一行

print(sum(map(int, String_Num.split())))

I had to use Google translate, but it looks like you are trying to sum the letters that are inputted.我不得不使用谷歌翻译,但看起来你正在尝试对输入的字母求和。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想使用 python 在 mysql 中创建一个表,我收到此错误,但我有名为 sam 的数据库,我该怎么办 - I want to make a table in mysql using python and i get this error but i have data base named sam what should i do 使用pycharm打开的Python无法满足我的要求 - Python with open using pycharm doesn't do what i want 如何在python中获取代码以执行我想要的操作? - how do I get my code in python to do what I want? 如果我使用 python 运行系统命令,并想得到它的动态结果,我该怎么办? - If I use python to run a system command, and want to get it's dynamic result, what should i do? for循环在python 3中没有做我想要它做的事情 - for looping in python 3 not doing what I want it to do 这段python代码是我想要的吗? - Is this python code doing what I want it to do? 如何总结我在 python 中选择的范围值 - How do I sum the range values I have selected in python 我想绕过标题并只有金额列的总和,我该怎么做? - I want to bypass the headers and have just the sum of the amount column, how do I do that? 如何以所需的格式获取Python日期? - How do I get my Python date in the format that I want? 我想用“%”号显示我的EXCEL数据。 我如何使用python做到这一点 - I want to display my EXCEL data with “%” sign. How can i do so by using python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM