Question: = Question-2: Write a Python program that takes a string as input containing binary numbers separated by multiple whitespaces and creates a dictionary where the

 = Question-2: Write a Python program that takes a string as

= Question-2: Write a Python program that takes a string as input containing binary numbers separated by multiple whitespaces and creates a dictionary where the keys will be corresponding decimals values of each binary number [You are not allowed to use any built-in conversion function to convert the binary values to its corresponding decimal values] Hint: Here is an example of converting a binary value 101101 to its decimal value: Decimal of 101101 = 1*(2**5) + 0*12**4) + 1* (2**3) + 1*2**2)+ 0*2*1) + 1*2**O) = 32 + 8+4+1 = 45 Sample Input 1: 101101 1010 11110 10101 10 101 1111 Sample Output 1: (45: 101101, 10:1010,30: 11110. 21: 10101, 2: 10,5 101,15 11111 Explanation: There are 7 numbers in the input string. The dictionary will contain the decimal and binary values of each number in key value pairs. Since the decimal of 101101 is 45, therefore, in the dictionary 101101 was added as the value of the key 45. Sample Input 2 1101 11 11001010110 Sample Output 2: {13: 1101, 3: 11,50: 110010, 22: 10110) Explanation2 There are 4 numbers in the input string. The dictionary will contain the decimal and binary values of each number in key:value pairs

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!