0

I'm using python 3.5.1 and I've had this problem with a few scripts. When I have multiple input() lines in a row, the ipython window will skip lines in between them. Here's my code:

def DMScalc(D, M, S):
    if D < 0.:
        DD = D + M*(-1)/60 + S*(-1)/3600
    else:
        DD = D + M/60 + S/3600
    return DD

print("\nConvert Degrees-Minutes-Seconds to Decimal Degrees")
D = float(input("Degrees: "))
M = float(input("Minutes: "))
S = float(input("Seconds: "))
print('Decimal Degrees:', end=' ')
print(DMScalc(D, M, S))

The ipython window shows the following:

Convert Degrees-Minutes-Seconds to Decimal Degrees

Degrees: 33

Minutes: 29

Seconds: 38
Decimal Degrees: 33.49388888888889

I'd like to remove the skipped lines above Degrees, Minutes, and Seconds so the end result is this:

Convert Degrees-Minutes-Seconds to Decimal Degrees
Degrees: 33
Minutes: 29
Seconds: 38
Decimal Degrees: 33.49388888888889

I checked the documentation for input() and it only talks about a trailing newline, which I don't think is the problem here.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Carson
  • 139
  • 1
  • 5

2 Answers2

0

With the input() function alone you can't.

Try the Curses library so you can take more control of terminal behaviour, because input() will always give you a new line.

Elvis Teixeira
  • 604
  • 4
  • 13
0

Carlos Cordoba, a Spyder developer, says this is a bug in their IPython console, see here:

How can I prevent Python from inserting a new line after taking user input?

You might check their Github repo to see if it has been fixed.

Here's the issue page if you're curious: https://github.com/jupyter/qtconsole/issues/262

Saedeas
  • 1,548
  • 8
  • 17