Gabriel Mercês
Gabriel Mercês

Reputation: 43

How to put the input() in the middle of the sentence (python)?

I would like to get the input() in the middle of the sentence.

I have tried:

print('I have ${} dollars'.format(float(input())))

and get this:

45 #asked before showing the print
I have $45 dollars

instead of this:

I have $| dollars #(The "|" means the place where the input() is requested)

Is that possible?

Upvotes: 0

Views: 122

Answers (1)

cmauck10
cmauck10

Reputation: 163

This is as close as you're going to get to what you want:

prefix = "I have $"
dollars = input(prefix)
ncols = len(dollars) + len(prefix) + 1
print(f"\033[F\033[{ncols}G dollars")
  • \033[F go to the (start of the) previous line
  • \03[{ncols}G move along ncols:

Upvotes: 1

Related Questions