Forums

print with parameter end="\t" or anything other than "\n" does not show anything

In a simple program to test math skills, I have the line

print('How much is '+str(number1)+' x '+str(number2)+'?', end="\n");

which works fine. But then the answer is typed on the next line. To be able to type right after the question I used end=" " and end="\t". But then if I run this line for a number of sums, the first question is never printed. After the first answer it goes fine.

Posts about other online Python interpreters (e.g., PyCharm) suggest that it may be a flushing issue, and that adding flush=True to the print statement or the line sys.stdout.flush(); after it will make it print. But in PythonAnywhere that is not the case.

Does anyone now a solution for this?

  1. are you using python3?
  2. are you using input to get the answers typed?
  3. if so why not put the stuff printed into the input call?
  1. yes, I run it from a file but at the start it says "loading python 3.6 interpreter"
  2. yes after the print statement I use answer=input();
  3. just tried answer=input('How much is '+str(number1)+' x '+str(number2)+'?'); and that does the trick!

Thanks! The print statement that I used first should also work in Python 3 though?

Sure, it should work though maybe there's some line buffering going on so it's only printing complete lines.