Nathan_S
Nathan_S

Reputation: 13

Can one print on the same line after user input?

I am relatively new to python and have to write a code for a "Countdown" based game; the program would basically ask the user for a word, see whether it is located in a file of words, and if it isn't print (directly after the word input by the user) "is invalid".

Here is the portion of code relative to this (I would supply the whole thing but I'm actually in France so it's in French...)

And here is what I see on my screen now, relative to what I have been asked for.

I'm also new to this forum so apologies in advance if this post isn't as polished as others!

Many thanks in advance to anyone willing to help, it's greatly appreciated!

Upvotes: 0

Views: 395

Answers (2)

jsbueno
jsbueno

Reputation: 110146

So, Python is a general purpose language, and just as any other language, it has nothing to do with the I/O capabilities - those are up to the ambient you are running it.

he built-in "input" has fixed behavior - and unless you change the terminal behavior for things like "turning echo off", it will just proceed to the next terminal line when the user press the return key.

Under Windows, the usual way to get more control over the terminal is to use the msvcrt library - not you'd have to build your own "input" function based on the several character-reading functions there. Actually if you are on Windows, that is likely the way your teacher wants you to follow.

On any other platform, the high-level way to do it is to use the curses library.

I hope you can find your way from there.

Upvotes: 0

Stan Vanhoorn
Stan Vanhoorn

Reputation: 534

You could do something like this:

def wordcheck(word):
    if ...:
        return word + " is valid"

    else:
        return word + " is invalid"

print("Proposed word: {0} ".format(wordcheck(input())))

Where "if ..." is you checking if the word is valid

Upvotes: 2

Related Questions