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:
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
add a comment |
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:
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
2
deleteinputFilterText()
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
add a comment |
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:
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
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:
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
python input
edited Nov 19 at 11:24
asked Nov 19 at 10:45
Roko
10312
10312
2
deleteinputFilterText()
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
add a comment |
2
deleteinputFilterText()
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
add a comment |
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.
Thanks, I didn't even realize haha
– Roko
Nov 19 at 11:05
add a comment |
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.
Sorry, I didn't know that I shouldn't
– Roko
Nov 19 at 11:05
add a comment |
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)
add a comment |
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.
Thanks, I didn't even realize haha
– Roko
Nov 19 at 11:05
add a comment |
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.
Thanks, I didn't even realize haha
– Roko
Nov 19 at 11:05
add a comment |
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.
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.
answered Nov 19 at 10:50
peterg
361
361
Thanks, I didn't even realize haha
– Roko
Nov 19 at 11:05
add a comment |
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
add a comment |
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.
Sorry, I didn't know that I shouldn't
– Roko
Nov 19 at 11:05
add a comment |
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.
Sorry, I didn't know that I shouldn't
– Roko
Nov 19 at 11:05
add a comment |
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.
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.
answered Nov 19 at 10:54
CUZLOCKED
10811
10811
Sorry, I didn't know that I shouldn't
– Roko
Nov 19 at 11:05
add a comment |
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
add a comment |
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)
add a comment |
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)
add a comment |
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)
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)
answered Nov 19 at 10:55
Jaba
6,563165292
6,563165292
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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