[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!
New course! Every coder should learn Generative AI!
Try a free lesson
0

[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.

22nd May 2022, 11:37 PM
Korkunç el Gato
Korkunç el Gato - avatar
10 Answers
+ 3
https://code.sololearn.com/c6Owj6OhhMC6/?ref=app
22nd May 2022, 11:55 PM
Simon Sauter
Simon Sauter - avatar
23rd May 2022, 12:14 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 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))
23rd May 2022, 1:50 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 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
23rd May 2022, 9:59 PM
Bob_Li
Bob_Li - avatar
+ 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
23rd May 2022, 5:17 AM
Brian
Brian - avatar
+ 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 💐
24th May 2022, 4:07 PM
Korkunç el Gato
Korkunç el Gato - avatar
+ 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.
23rd May 2022, 12:42 AM
Korkunç el Gato
Korkunç el Gato - avatar
+ 1
Rik Wittkopp Thank you for the link, I don't know most of these :-)
23rd May 2022, 2:01 AM
Korkunç el Gato
Korkunç el Gato - avatar
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.
23rd May 2022, 12:03 AM
Korkunç el Gato
Korkunç el Gato - avatar