print() prints only every second input











up vote
-3
down vote

favorite












I'm new to python and I've been trying to make a little function to call upon when I need to filter an input from everything except regular letters.

I've used SO for parts of the code, but I can't seem to understand why does it only print on every second try.

Here's my code:



import re
i=1

def inputFilterText():
inputRaw = input('input: ')
inputFiltered = re.sub('[^a-zA-Z]+', '', inputRaw)
return inputFiltered

while i > 0:
inputFilterText()
print(inputFilterText())


And here's my output:



output



I'm not really sure what's going on, but I presume it's a logical error. I've only just started using Python so any help is appreciated.



PS
The 'while' is only there so it's easier to test, it can be omitted.










share|improve this question




















  • 2




    delete inputFilterText() line, you never print the return value from every other try (including the first)
    – Chris_Rands
    Nov 19 at 10:47








  • 4




    Please include your code as formatted text in your question. Pictures of code (or other text) are not appropriate.
    – khelwood
    Nov 19 at 10:47












  • Fixed it, sorry
    – Roko
    Nov 19 at 11:08










  • @Wombatz it was accidental, edited again
    – Roko
    Nov 19 at 11:25















up vote
-3
down vote

favorite












I'm new to python and I've been trying to make a little function to call upon when I need to filter an input from everything except regular letters.

I've used SO for parts of the code, but I can't seem to understand why does it only print on every second try.

Here's my code:



import re
i=1

def inputFilterText():
inputRaw = input('input: ')
inputFiltered = re.sub('[^a-zA-Z]+', '', inputRaw)
return inputFiltered

while i > 0:
inputFilterText()
print(inputFilterText())


And here's my output:



output



I'm not really sure what's going on, but I presume it's a logical error. I've only just started using Python so any help is appreciated.



PS
The 'while' is only there so it's easier to test, it can be omitted.










share|improve this question




















  • 2




    delete inputFilterText() line, you never print the return value from every other try (including the first)
    – Chris_Rands
    Nov 19 at 10:47








  • 4




    Please include your code as formatted text in your question. Pictures of code (or other text) are not appropriate.
    – khelwood
    Nov 19 at 10:47












  • Fixed it, sorry
    – Roko
    Nov 19 at 11:08










  • @Wombatz it was accidental, edited again
    – Roko
    Nov 19 at 11:25













up vote
-3
down vote

favorite









up vote
-3
down vote

favorite











I'm new to python and I've been trying to make a little function to call upon when I need to filter an input from everything except regular letters.

I've used SO for parts of the code, but I can't seem to understand why does it only print on every second try.

Here's my code:



import re
i=1

def inputFilterText():
inputRaw = input('input: ')
inputFiltered = re.sub('[^a-zA-Z]+', '', inputRaw)
return inputFiltered

while i > 0:
inputFilterText()
print(inputFilterText())


And here's my output:



output



I'm not really sure what's going on, but I presume it's a logical error. I've only just started using Python so any help is appreciated.



PS
The 'while' is only there so it's easier to test, it can be omitted.










share|improve this question















I'm new to python and I've been trying to make a little function to call upon when I need to filter an input from everything except regular letters.

I've used SO for parts of the code, but I can't seem to understand why does it only print on every second try.

Here's my code:



import re
i=1

def inputFilterText():
inputRaw = input('input: ')
inputFiltered = re.sub('[^a-zA-Z]+', '', inputRaw)
return inputFiltered

while i > 0:
inputFilterText()
print(inputFilterText())


And here's my output:



output



I'm not really sure what's going on, but I presume it's a logical error. I've only just started using Python so any help is appreciated.



PS
The 'while' is only there so it's easier to test, it can be omitted.







python input






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 11:24

























asked Nov 19 at 10:45









Roko

10312




10312








  • 2




    delete inputFilterText() line, you never print the return value from every other try (including the first)
    – Chris_Rands
    Nov 19 at 10:47








  • 4




    Please include your code as formatted text in your question. Pictures of code (or other text) are not appropriate.
    – khelwood
    Nov 19 at 10:47












  • Fixed it, sorry
    – Roko
    Nov 19 at 11:08










  • @Wombatz it was accidental, edited again
    – Roko
    Nov 19 at 11:25














  • 2




    delete inputFilterText() line, you never print the return value from every other try (including the first)
    – Chris_Rands
    Nov 19 at 10:47








  • 4




    Please include your code as formatted text in your question. Pictures of code (or other text) are not appropriate.
    – khelwood
    Nov 19 at 10:47












  • Fixed it, sorry
    – Roko
    Nov 19 at 11:08










  • @Wombatz it was accidental, edited again
    – Roko
    Nov 19 at 11:25








2




2




delete inputFilterText() line, you never print the return value from every other try (including the first)
– Chris_Rands
Nov 19 at 10:47






delete inputFilterText() line, you never print the return value from every other try (including the first)
– Chris_Rands
Nov 19 at 10:47






4




4




Please include your code as formatted text in your question. Pictures of code (or other text) are not appropriate.
– khelwood
Nov 19 at 10:47






Please include your code as formatted text in your question. Pictures of code (or other text) are not appropriate.
– khelwood
Nov 19 at 10:47














Fixed it, sorry
– Roko
Nov 19 at 11:08




Fixed it, sorry
– Roko
Nov 19 at 11:08












@Wombatz it was accidental, edited again
– Roko
Nov 19 at 11:25




@Wombatz it was accidental, edited again
– Roko
Nov 19 at 11:25












3 Answers
3






active

oldest

votes

















up vote
2
down vote



accepted










You are calling inputFilterText twice. Once within the print() and once before. This is causing the code to prompt for input twice before printing the second response.






share|improve this answer





















  • Thanks, I didn't even realize haha
    – Roko
    Nov 19 at 11:05


















up vote
1
down vote













The problem is that you make a call to the inputFilterText function twice. The first time the output is discarded. Causing input to be taken twice, but only showing a result once.



To fix it, remove the inputFilterText() line. An example of working code.



import re
i=1

def inputFilterText():
inputRaw = input("input: ")
inputFiltered = re.sub(""[^a-zA-Z]+, "", inputRaw)
return inputFiltered

while i > 0:
print(inputFilterText())


Also, in future please send code as raw text, rather than screenshots.






share|improve this answer





















  • Sorry, I didn't know that I shouldn't
    – Roko
    Nov 19 at 11:05


















up vote
1
down vote













Might I suggest using a variable here, you're not doing anything with the first filter call (this is why it's asking the first time) and the second one you're only printing.



while True:
txt = inputFilterText()
#do some stuff if needed
print(txt)





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372927%2fprint-prints-only-every-second-input%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    You are calling inputFilterText twice. Once within the print() and once before. This is causing the code to prompt for input twice before printing the second response.






    share|improve this answer





















    • Thanks, I didn't even realize haha
      – Roko
      Nov 19 at 11:05















    up vote
    2
    down vote



    accepted










    You are calling inputFilterText twice. Once within the print() and once before. This is causing the code to prompt for input twice before printing the second response.






    share|improve this answer





















    • Thanks, I didn't even realize haha
      – Roko
      Nov 19 at 11:05













    up vote
    2
    down vote



    accepted







    up vote
    2
    down vote



    accepted






    You are calling inputFilterText twice. Once within the print() and once before. This is causing the code to prompt for input twice before printing the second response.






    share|improve this answer












    You are calling inputFilterText twice. Once within the print() and once before. This is causing the code to prompt for input twice before printing the second response.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 19 at 10:50









    peterg

    361




    361












    • Thanks, I didn't even realize haha
      – Roko
      Nov 19 at 11:05


















    • Thanks, I didn't even realize haha
      – Roko
      Nov 19 at 11:05
















    Thanks, I didn't even realize haha
    – Roko
    Nov 19 at 11:05




    Thanks, I didn't even realize haha
    – Roko
    Nov 19 at 11:05












    up vote
    1
    down vote













    The problem is that you make a call to the inputFilterText function twice. The first time the output is discarded. Causing input to be taken twice, but only showing a result once.



    To fix it, remove the inputFilterText() line. An example of working code.



    import re
    i=1

    def inputFilterText():
    inputRaw = input("input: ")
    inputFiltered = re.sub(""[^a-zA-Z]+, "", inputRaw)
    return inputFiltered

    while i > 0:
    print(inputFilterText())


    Also, in future please send code as raw text, rather than screenshots.






    share|improve this answer





















    • Sorry, I didn't know that I shouldn't
      – Roko
      Nov 19 at 11:05















    up vote
    1
    down vote













    The problem is that you make a call to the inputFilterText function twice. The first time the output is discarded. Causing input to be taken twice, but only showing a result once.



    To fix it, remove the inputFilterText() line. An example of working code.



    import re
    i=1

    def inputFilterText():
    inputRaw = input("input: ")
    inputFiltered = re.sub(""[^a-zA-Z]+, "", inputRaw)
    return inputFiltered

    while i > 0:
    print(inputFilterText())


    Also, in future please send code as raw text, rather than screenshots.






    share|improve this answer





















    • Sorry, I didn't know that I shouldn't
      – Roko
      Nov 19 at 11:05













    up vote
    1
    down vote










    up vote
    1
    down vote









    The problem is that you make a call to the inputFilterText function twice. The first time the output is discarded. Causing input to be taken twice, but only showing a result once.



    To fix it, remove the inputFilterText() line. An example of working code.



    import re
    i=1

    def inputFilterText():
    inputRaw = input("input: ")
    inputFiltered = re.sub(""[^a-zA-Z]+, "", inputRaw)
    return inputFiltered

    while i > 0:
    print(inputFilterText())


    Also, in future please send code as raw text, rather than screenshots.






    share|improve this answer












    The problem is that you make a call to the inputFilterText function twice. The first time the output is discarded. Causing input to be taken twice, but only showing a result once.



    To fix it, remove the inputFilterText() line. An example of working code.



    import re
    i=1

    def inputFilterText():
    inputRaw = input("input: ")
    inputFiltered = re.sub(""[^a-zA-Z]+, "", inputRaw)
    return inputFiltered

    while i > 0:
    print(inputFilterText())


    Also, in future please send code as raw text, rather than screenshots.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 19 at 10:54









    CUZLOCKED

    10811




    10811












    • Sorry, I didn't know that I shouldn't
      – Roko
      Nov 19 at 11:05


















    • Sorry, I didn't know that I shouldn't
      – Roko
      Nov 19 at 11:05
















    Sorry, I didn't know that I shouldn't
    – Roko
    Nov 19 at 11:05




    Sorry, I didn't know that I shouldn't
    – Roko
    Nov 19 at 11:05










    up vote
    1
    down vote













    Might I suggest using a variable here, you're not doing anything with the first filter call (this is why it's asking the first time) and the second one you're only printing.



    while True:
    txt = inputFilterText()
    #do some stuff if needed
    print(txt)





    share|improve this answer

























      up vote
      1
      down vote













      Might I suggest using a variable here, you're not doing anything with the first filter call (this is why it's asking the first time) and the second one you're only printing.



      while True:
      txt = inputFilterText()
      #do some stuff if needed
      print(txt)





      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        Might I suggest using a variable here, you're not doing anything with the first filter call (this is why it's asking the first time) and the second one you're only printing.



        while True:
        txt = inputFilterText()
        #do some stuff if needed
        print(txt)





        share|improve this answer












        Might I suggest using a variable here, you're not doing anything with the first filter call (this is why it's asking the first time) and the second one you're only printing.



        while True:
        txt = inputFilterText()
        #do some stuff if needed
        print(txt)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 10:55









        Jaba

        6,563165292




        6,563165292






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372927%2fprint-prints-only-every-second-input%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy