wt change i hv to make in this code to get decimal output frm binary | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
- 1

wt change i hv to make in this code to get decimal output frm binary

def decToBinConversion(no, precision): binary = "" IntegralPart = int(no) fractionalPart = no- IntegralPart #to convert an integral part to binary equivalent while (IntegralPart): re = IntegralPart % 2 binary += str(re) IntegralPart //= 2 binary = binary[ : : -1] binary += '.' #to convert an fractional part to binary equivalent while (precision): fractionalPart *= 2 bit = int(fractionalPart) if (bit == 1) : fractionalPart -= bit binary += '1' else : binary += '0' precision -= 1 return binary no = float(input()) k = int(input()) print("Binary Equivalent:",decToBinConversion(no,k))

13th Jun 2021, 5:54 AM
Madhava Raj B
Madhava Raj B - avatar
1 ответ
+ 1
well, another copy-paste from another source with another issue: the new lines characters and tabulations are gone ^^ you should reformat it (help you from the source wich should show the correct format) and see if it works ;P
13th Jun 2021, 6:08 AM
visph
visph - avatar