We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Strings
- String Formatting
- Discussions
String Formatting
String Formatting
Sort by
recency
|
1737 Discussions
|
Please Login in order to post a comment
def print_formatted(number): # your code goes here G=len(bin(number)[2:]) for i in range(1,number+1): dec=str(i) octal=oct(i)[2:] hexa=hex(i)[2:].upper() binary=bin(i)[2:] print(dec.rjust(G),octal.rjust(G),hexa.rjust(G),binary.rjust(G))
if name == 'main': n = int(input()) print_formatted(n)
Python’s built-in formatting tools make aligning and structuring data output super intuitive once you get the hang of it. 11xplay login id and password
It’s a great exercise for mastering alignment, spacing, and clean output formatting using f-strings, Cricbet99 login ID and Password
So, I love f-strings. This was the first time I've seen where something seemed a bit more hacky than with format strings, but I made it work. In particular, the start_pad bothers me, not sure why
>{pad}d
did not work.The [2:] is to strip the '0b' off the start of the return value from bin().