filmov
tv
String Formatting [HackerRank] | Python | rjust() | oct() | hex() | bin()
Показать описание
This video is about String Formatting problem from HackerRank.
Problem Statement:
Given an integer, n , print the following values for each integer i from 1 to n:
Decimal
Octal
Hexadecimal (capitalized)
Binary
#HackerRank #String #Python
Problem:
Sample code:
def print_formatted(number):
w=len(str(bin(number))[2:])
for i in range(1,number+1):
print(str(i).rjust(w,' '),oct(i)[2:].rjust(w,' '),hex(i)[2:].upper().rjust(w,' '),bin(i)[2:].rjust(w,' '))
For 1 : 1 Tutoring
WhatsApp contact : 7278222619
Follow me on:
whatsapp:
Facebook:
Linkedin:
Instagram:
Problem Statement:
Given an integer, n , print the following values for each integer i from 1 to n:
Decimal
Octal
Hexadecimal (capitalized)
Binary
#HackerRank #String #Python
Problem:
Sample code:
def print_formatted(number):
w=len(str(bin(number))[2:])
for i in range(1,number+1):
print(str(i).rjust(w,' '),oct(i)[2:].rjust(w,' '),hex(i)[2:].upper().rjust(w,' '),bin(i)[2:].rjust(w,' '))
For 1 : 1 Tutoring
WhatsApp contact : 7278222619
Follow me on:
whatsapp:
Facebook:
Linkedin:
Instagram: