PYTHON BASIC PROBLEMS SOLUTIONS(HACKERRANK) Day-24LEARN CODING EASILY. HOW TO BECOME GOOD PROGRAMMER

Veröffentlicht am: 17 Februar 2022
auf dem Kanal: TECHPARK
32
1

HII Young Coders our channel will give you Hackerrank solutions.It will be very useful for you Kindly make use of it.

PROBLEM LINK:

https://www.hackerrank.com/challenges...

PROBLEM:

Given an integer, n, print the following values for each integer i from 1 to n: :

1.Decimal
2.Octal
3.Hexadecimal (capitalized)
4.Binary

FUNCTION DESCRIPTION:

Complete the print_formatted function in the editor below.

print_formatted has the following parameters:

int number: the maximum value to print

Prints

The four values must be printed on a single line in the order specified above for each i from 1 to number. Each value should be space-padded to match the width of the binary value of number and the values should be separated by a single space.

INPUT FORMAT

A single integer denoting .n

SAMPLE INPUT

17
SAMPLE OUTPUT:

1 1 1 1
2 2 2 10
3 3 3 11
4 4 4 100
5 5 5 101
6 6 6 110
7 7 7 111
8 10 8 1000
9 11 9 1001
10 12 A 1010
11 13 B 1011
12 14 C 1100
13 15 D 1101
14 16 E 1110
15 17 F 1111
16 20 10 10000
17 21 11 10001

SOLUTION:

def print_formatted(number):

results=[]
for i in range(1, n+1):
decimal = str(i)
octal = str(oct(i)[2:])
hex_ = str(hex(i)[2:]).upper()
binary = str(bin(i)[2:])

results.append([decimal, octal, hex_, binary])

width = len(results[-1][3]) # largest binary number

for i in results:
print(*(rep.rjust(width) for rep in i))


Auf dieser Seite können Sie das Online-Video PYTHON BASIC PROBLEMS SOLUTIONS(HACKERRANK) Day-24LEARN CODING EASILY. HOW TO BECOME GOOD PROGRAMMER mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer TECHPARK 17 Februar 2022 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 32 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!