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

Adding Characters to an Empty String in Python

I am attempting to have my program iterate over a user-inputted string and print it again, with a "u" in place of every uppercase letter, an "l" in place of every lowercase letter, and a "-" in place of any other character. This is what I have written:

txt = input()
modified_txt = ""

for char in txt:
    if char.isupper():
        modified_txt + "u"
    elif char.islower():
        modified_txt + "l"
    else:
        modified_txt + "-"

print(modified_txt)

For some reason, my output is a blank line, as though the variable "modified_txt" was never affected by the for loop. I’m sure there’s a straightforward reason why this is the case but I’m at a loss.

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

>Solution :

maybe you need add + characters before =

txt = input()
modified_txt = ""

for char in txt:
    if char.isupper():
        modified_txt += "u"
    elif char.islower():
        modified_txt += "l"
    else:
        modified_txt += "-"

print(modified_txt)
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