QUESTION

Text
Image

Please help me with the code for deliverable #2, I have provided all necessary information


Computer Representations Computers natively represent numbers in binary. When we interact with computers, the internal representation is converted to a string of characters that are convenient for humans, be that decimal, hexadecimal, or otherwise. So, we are going to implement functions that translate to and from the internal representation and several arbitrary bases: - Binary (base 2) - Octal (base 8) - Decimal (base 10) - Duodecimal (base 12) ${ }^{1}$ - Hexadecimal (base 16) - Cuneiform (base 60) - Garblaxian (base 60) The next cell defines the sets of digits each of these systems employ. [n $[4]$ : base $2=' 01$ ' base $8=' 01234567 '$ base10 $=' 0123456789$ ' base $16=$ '0123456789ABCDEF' duodecimal $=' 0123456789 \mathrm{AB} '$ Ideally, your implementation of each function will support any and all of these counting systems. However, since the representation in the Babylonian system are composed of two UTF8 characters per digit, the tests for each deliverable will not prevent you from working on the remaining deliverables in this project. [ 5 ] : def expectEqual (a, b) : if a $!=$ b: print('FAIL expected:', b,' got:', a)

Aliens = 'ᐁᐃᐄᐅᐆᐇᐉᐊᐋᐖᐛᐯᐱᐲᐳᐴᐵᐷᐸᐹᑀᑂᑅᑇᑈᑌᑍᑎᑏᑐᑑᑒᑓᑔᑕᑖᑝᑟᑢᑤᑥᑫᑭᑮᑯᑰᑱᑲᒉᒋᒌᒍᒏᒐᒒᒕᒗᒘ'

Babylonian = ['??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??','??']


Deliverable \#2: General String to Integer Implement a number parser. The function should take a string representation of a number and a base and convert the string into a Python integer. def stringToInt(number, base): \#implement code here return 0 expectEqual (stringToInt ('20', base10), 20) expectEqual (stringToInt('31337', base10), 31337) expectEqual (stringToInt('10100', base2), 20) expectEqual (stringToInt ('111101001101001', base2), 31337) expectEqual (stringToInt (' 20 ', base 8 ), 16) expectEqual (stringToInt ('31337', base8), 13023) expectEqual (stringToInt ('20', base16), 32) expectEqual (stringToInt(' 31337 ', base16), 201527) expectEqual (stringToInt (' $\rangle$ ', aliens), 20) expectEqual (stringToInt('《O', babylonian), 20) expectEqual(stringToInt(' $\| \mathrm{III}$ ', babylonian), 123)

Public Answer

PUDMT3 The First Answerer