0

I'm writing a very simple prompt-input sequence:

print "question",
a = raw_input()
print "question",
b = raw_input()
print "question",
c = raw_input()
print "question",
d = raw_input()

print "Your answers were: %r, %r, %r and %r" % (a, b, c, d)

The problem is: when running the code in bash, it asks directly for all four inputs before printing the questions. Any idea why this could be happening?

Edit: the solution offered in the duplicate candidate "solves" the problem (although after the first input the questions are printed with one space indentation, for some reason I don't yet know). I'm working from an exercise book that insists the code should be transcribed exactly and makes no mention of flushing the buffer.

user62099
  • 11
  • 2
  • Possible duplicate of [python \`print\` does not work in loop](https://stackoverflow.com/questions/25368786/python-print-does-not-work-in-loop) – glibdud Jan 18 '19 at 14:50
  • The duplicate candidate explains why you're getting this behavior, but what you actually probably want is to use the `prompt` argument to [`raw_input()`](https://docs.python.org/2/library/functions.html#raw_input), e.g. `a = raw_input("question")` – glibdud Jan 18 '19 at 14:52
  • @glibdud: Yeah, I thought of using prompt arguments. I just wanted to know precisely why this example didn't work, since it is copied to the letter directly from a book. – user62099 Jan 18 '19 at 15:26

0 Answers0