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.
defprint_formatted(number):#get the width of the binary part of numberwidth=len(bin(number))-2foriinrange(1,number+1):#don't worry if it shows some red braces!#program is still correctprint(f"{i:{width}d}{i:{width}o}{i:{width}X}{i:{width}b}")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 →