Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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)

>Solution :

Add just one line after the ‘print(String_Num)’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading