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

How do I define a variable with 2 outputs in Python?

I have this problem that I can´t solve.
I have this function:

def ex2(tex_ori):
    let = ("a" or "A")
    text_troc = tex_ori.replace(let, "x")
    return text_troc

And the execution for this is:

text_ori = input("Write a sentence: ")
     text_1 = ex2(text_ori)
     print(text_1)

But the only letter being replaced is just "a".
What am I doing wrong and what should i do?

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

I am expecting that all letters "a" and "A" are replaced with the letter "x".
For an example:
Sentence: Hi my name is Alex.
The return should be: Hi my nxme is xlex.

Thanks for the attention and help.

>Solution :

When you write let = ("a" or "A") the let variable will store only the first true statement from the two (in this case "a"). In order to replace both letters you can write it for example this way:

def ex2(tex_ori):
    text_troc = tex_ori.replace("a", "x")
    text_troc = text_troc.replace("A", "x")
    return text_troc

text_ori = input("Write a sentence: ")
text_1 = ex2(text_ori)
print(text_1)
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