May-19-2020, 02:31 PM
Hey,
I missed a coding class today and I didn't understand at all the script we have been given for homework. We are supposed to write and input and the output from the script but I still want to understand the script. The script converts a number in a binary base to decimal. (It's in the newest python version available as I am writing this).
I missed a coding class today and I didn't understand at all the script we have been given for homework. We are supposed to write and input and the output from the script but I still want to understand the script. The script converts a number in a binary base to decimal. (It's in the newest python version available as I am writing this).
bin_num = int(input("Insert binary number: "))
dec_num = 0
num = bin_num
m=0
while num>0:
digit = num%10
p = 2**m
dec_num = dec_num+digit*p
num=num//10
m+=1
print(bin_num,"(2)= ",dec_num,"(10)")
print ("Name classmethod")
