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
|
1707 Discussions
|
Please Login in order to post a comment
def print_formatted(number):
def print_formatted(number): wid = len(bin(number))-2 for i in range(1, number+1): print(f"{i:{wid}d} {i:{wid}o} {i:{wid}X} {i:{wid}b}") if name == 'main': n = int(input()) print_formatted(n)
Script kiddie here. I'm thinking that I could replace removeprefix with some sort of replace syntax. (giving credit to Anisha for a clean script)
for a in range(number): #First we set up up a range w = len(format(number, 'b')) a=a+1 b = str(a) print(b.rjust(w), oct(a).removeprefix("0o").rjust(w),hex(a).removeprefix("0x").rjust(w).upper(),bin(a).removeprefix("0b").rjust(w))