Write a Python program to find the sum of the binary numbers in list L, where the binary numbers do not have the quote marks necessary for the int() function. For example, if L = [101, 11, 1010] then the sum is 5 + 3 + 10 = 18. What is the sum when L is L = [10100, 101000, 100000, 1011111, 1000, 1010111, 1010010, 11001, 101100, 10111, 11011, 1011010, 11101, 10, 110011, 1001111, 110010, 101100, 100001, 111001]
Python code:
#intializing list L with the given values
L=[10100,101000,100000,1011111,1000,1010111,1010010,11001,101100,10111,11011,1011010,11101,10,110011,1001111,110010,101100,100001,111001]
#intializing sum as 0
sum=0
#looping each element in L
for i in L:
#adding to sum the integer value of the number
sum+=int(str(i),2)
#printing sum
print(sum)
Screenshot:
Output:
Get Answers For Free
Most questions answered within 1 hours.