[Slvd]Is there a way in Python to get inputs in loops to right-align, with space counted from the right edge of console screen? | Sololearn: Learn to code for FREE!

+1

[Slvd]Is there a way in Python to get inputs in loops to right-align, with space counted from the right edge of console screen?

So that it's the last digits of input that align? for i in range(3): n = int(input()) console: 15 215 3 I looked things up, they weren't of much help, and I am going to elaborate on my question if you find it unclear, but I am trying to avoid a wall of text. Thank you all.

5/22/2022 11:37:59 PM

Korkunç the Terrible Frusciante

10 Answers

New Answer

+4

https://www.geeksforgeeks.org/python-string-ljust-rjust-center/

+3

https://code.sololearn.com/c6Owj6OhhMC6/?ref=app

+3

https://code.sololearn.com/cdOI5gGxI12x/?ref=app

+3

Korkunç TheTerrible Python built_in String methods. Worth playing with https://www.w3schools.com/python/python_ref_string.asp example print("Python example".rjust(20))

+3

Korkunç the Terrible Frusciante Lots of great suggestions. I didn't see any f-string, which is the first thing that came to my mind. f-string does the string conversion for you. or maybe you should use a tabular data format instead? https://code.sololearn.com/cD8Jvp5xwNDE/?ref=app

+2

Here is how you could implement your own custom right justifier with limited field width. # Insert fill characters before the string, # then slice by -width from the right end. # # Indicate width overrun with all '#'s. def rjust(s, width=10, fill=' '): if len(s)>width: s = '#'*width #overrun return (fill*width + s)[-width:] for i in range(3): n = input() print(rjust(n)) https://code.sololearn.com/c59zxwd8XhZ0/?ref=app

+2

Brian and Bob_Li I saved them all and am going to work with them on my pc. (and yes, I was wondering if there was a way to give it a tabular look) Many thanks πŸ’

+1

Also these are both great, I'll wait and tick whichever reply learners like the most, this is hard for me. I'm reluctantly gathering that there's no module with a function that directly manipulates input alignment πŸ˜… I will save these, though, I will have a go at it myself too:-) Thank you both.

+1

Rik Wittkopp Thank you for the link, I don't know most of these :-)

0

So I have to always turn it into a string unless I define a function myself doing Simon Sauter's code does. Thank you Simon Sauter. I think I'll have to rewrite sthg I today if I wanna format it so much. But I would want to, if it were 1000 lines of input I guess.