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.
decimal_num = []
def print_formatted(number):
# your code goes here
r=0
decimal_num = list(range(1,number+1))
octal = []
for i in decimal_num:
if(i<=7):
octal.append(i)
if(i>7):
l = i//8
r = i % 8
octal.append(int(str(l)+str(r)))
#print(decimal_num,"\n",octal)
Hexa_num = []
for num in decimal_num:
Hexa_num.append((hex(num).upper()).lstrip('0X'))
#print(Hexa_num)
binary_num = []
for i in decimal_num:
binary_num.append(bin(i).lstrip('0b'))
#print(binary_num)
width = len(binary_num[-1])
for num in range(number):
print(f"{decimal_num[num]:>{width}} {octal[num]:>{width}} {Hexa_num[num]:>{width}} {binary_num[num]:>{width}}")
return
if name == 'main':
n = int(input())
print_formatted(n)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
String Formatting
You are viewing a single comment's thread. Return to all comments →
decimal_num = [] def print_formatted(number): # your code goes here r=0 decimal_num = list(range(1,number+1))
if name == 'main': n = int(input()) print_formatted(n)