Thisura
Thisura

Reputation: 40

How can I get an input between two print() functions without going to the next line?

I am trying to build this receipt kind of structure.

This is what I am trying to code

This is my code:

print('--------------------------------')
print('|\tGEOMETRICAL FIGURE\t|')
print('|\t     CALCULATIONS\t|')
print('--------------------------------')
print('|\tFigure:\t\t\t|')
print('|\t1. Circle\t\t|')
print('|\t2. Triangle\t\t|')
print('|\t3. Ellipse\t\t|')
print('|\t4. Trapezium\t\t|')
print('--------------------------------')
print('|\tType number desired\t|')
print('|\t\t',end = '');num = int(input());print('\t\t|')
print('--------------------------------')

I am getting this as the output (5 is the user input I gave):

The Output

How can I get those into one single line?

Upvotes: 0

Views: 63

Answers (2)

Andrey.Maralin
Andrey.Maralin

Reputation: 53

Try to use one print instead.

print(f"|\t\t{int(input())}\t\t|")

Upvotes: 1

LtWorf
LtWorf

Reputation: 7598

I don't think you can. The new line is what the user types, it doesn't come from your program.

To have more fine control over what's on the terminal you need to use curses, that's much more complicated to use, but I think it's the way to go, so you can handle all cases, including errors.

Another way is to turn off the echo in the terminal, so that the typed stuff will not appear on screen. However you'll have to read digit by digit instead of using input and display it or the user won't see anything.

Upvotes: 1

Related Questions