Input jumps line, how not to jump in Python?

Asked

Viewed 550 times

-1

How do I use input and prevent it from skipping a line before the next one in Python? for example:

Digite N: 1
Digite dígito para A: 5
Digite dígito para E: 9
Digite x: 8.25
Digite y: 7.3
Errou
Código: 9

my code returns that:

Digite N: 1

Digite dígito para A: 5

Digite dígito para E: 9

Digite x: 8.25

Digite y: 7.3
    Errou
Código:  9
  • 1

    What do you mean? The user wouldn’t have to press Enter to confirm the entry? this would already skip a line

  • good, that’s right. and how to stop it from jumping?

  • Input() does not skip line. It will drop to the bottom line when the user presses enter. The result is the same as you asked the question.

  • showw, thanks a bro!!!!

  • then @nosklo , I edited the question, now it’s chlorine the difference

  • @But I don’t know how you got this second result without seeing your code. I did it here and it looked like you wanted it; it’s not skipping any line here.

  • 2

    Tiago, please edit your question and add your code. Only with the output there is no way to check what is wrong.

  • It has already improved a lot with its edition, but it lacks the [mcve] with the problem for the community to identify the problem.

Show 3 more comments

3 answers

1

To avoid skipping lines, nothing needs to be done - the input() no longer jumps lines as you showed in your question.

There must be some something else wrong in your code, which is causing this line jump, because this is not the normal behavior of the function input() python.

  • 2

    I’d say it’s something like... print(input('Bazinga?'))

  • 1

    bola_de_cristal(input('Sem código?'))

1

I don’t think it’s possible. But an alternative would be to do so:

entrada = input()
x, y = entrada.split()

or

entrada = input().split()
x = entrada[0]
y = entrada[1]

remembering that split() can only be used in strings so if you need the values to be int, for example, just convert, like this:

x = int(entrada[0])
  • thanks, but I can’t use methods

  • Look, I think the input() will always skip line, but if you figure out how to do it, let me know.

  • ok. Tks. anything warning yes

0

Look your question is not very clear to me yet, but from what I understand you want this.

linha = ''
inseridos = []

while True:
    if linha != 'ABC': 
        linha = input("Insira string\n")
        inseridos.append(linha)
    else:
        print(inseridos)
        break

Code for when entering 'ABC', and the result is a list, which you can handle easily.

  • so the question is simple, it asks N and skips one line before asking A and skips another before asking E ... etc. I want it not to skip that line as in the example above

Browser other questions tagged

You are not signed in. Login or sign up in order to post.