A main function that tests the conversion function with In Chapter 4, we developed an algorithm for converting from binary to decimal. You can generalize this algorithm numbers in several bases has...


python coding


A main function that tests the conversion function with<br>In Chapter 4, we developed an algorithm for converting<br>from binary to decimal. You can generalize this algorithm numbers in several bases has been provided.<br>to work for a representation in any base. Instead of using<br>a power of 2, you will write a program that converts any<br>An example of main and correct output is shown below:<br>base between 2 and 16. Recall that for numbers 10 - 15<br>we use letters A - F.<br>def main():<br>print(repToDecimal('10', 10))<br>In convert.py, define a function named repToDecimal<br>that expects two arguments, a string, and an integer. The<br>print(repToDecimal('10', 8))<br>second argument should be the base. For example,<br>print(repToDecimal('10', 2))<br>print(repToDecimal('10', 16))<br>repToDecimal(

Extracted text: A main function that tests the conversion function with In Chapter 4, we developed an algorithm for converting from binary to decimal. You can generalize this algorithm numbers in several bases has been provided. to work for a representation in any base. Instead of using a power of 2, you will write a program that converts any An example of main and correct output is shown below: base between 2 and 16. Recall that for numbers 10 - 15 we use letters A - F. def main(): print(repToDecimal('10', 10)) In convert.py, define a function named repToDecimal that expects two arguments, a string, and an integer. The print(repToDecimal('10', 8)) second argument should be the base. For example, print(repToDecimal('10', 2)) print(repToDecimal('10', 16)) repToDecimal("10", 8) returns 8, whereas repToDecimal("10", 16) returns 16. The function should use a lookup table to find the value of any digit. Make sure that this table (it is 10 actually a dictionary) is initialized before the function 8 is defined. 2 convert.py + 16 • For its keys, use the 10 decimal digits (all strings) and 1 # Put your code here the letters A... F (all uppercase). The value stored 2 3 # A main for testing your program with each key should be the integer that the digit 4 def main(): represents. (The letter A associates with the integer 5 ""Tests the function.""" print(repToDecimal('10', 10)) print(repToDecimal('10', 8)) print(repToDecimal('10', 2)) print(repToDecimal('10', 16)) value 10, and so on.) 7 • The main loop of the function should convert each 8 9. digit to uppercase, look up its value in the table, and 10 use this value in the computation. 11 # The entry point for program execution "_main__": 12 if -_name__ == main() A main function that tests the conversion function with 13 14 numbers in several bases has been provided.
Jun 03, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here