[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?
10 AnswersNew Answer
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 PMKorkunç the Terrible Frusciante
10 AnswersNew Answer
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))
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
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
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 💐
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.
Rik Wittkopp Thank you for the link, I don't know most of these :-)
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.
Sololearn Inc.535 Mission Street, Suite 1591
Send us a message