Question: Python Program Explanation Program is correct all I need is an explanation line by line to better understand the algorithm of the program. Thanks in
Python Program Explanation
Program is correct all I need is an explanation line by line to better understand the algorithm of the program. Thanks in advanced
def main(): start = int(input("Enter the starting number: ")) end = int(input("Enter the ending number: ")) print("Decimal\t\tBinary\t\tOctal\t\tHexadecimal") for i in range(start, end + 1): x = decToBinary(i) y = decToOctal(i) z = decToHexa(i) print(i, "\t\t", end=" ") print("".join(str(j) for j in x), "\t\t", end=" ") print("".join(str(q) for q in y), "\t\t", end=" ") print("".join(str(r) for r in z))
def decToBinary(decimal): a = [] while(decimal > 0): dig = decimal % 2 a.append(dig) decimal = decimal // 2 a.reverse() return a
def decToOctal(decimal): a = [] octalNum = [0] * 100 i = 0 while(decimal != 0): octalNum[i] = decimal % 8 decimal = int(decimal / 8) i += 1 for j in range(i - 1, -1, -1): a.append(octalNum[j]) return a
def decToHexa(decimal): a = [] hexaNum = [0] * 100 i = 0 while(decimal != 0): temp = 0 temp = decimal % 16 if(temp < 10): hexaNum[i] = chr(temp + 48) i = i + 1 else: hexaNum[i] = chr(temp + 55) i = i + 1 decimal = int(decimal / 16) j = i - 1 while(j >= 0): a.append(hexaNum[j]) j = j - 1 return a
main()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
