In Chapter 4, we developed an algorithm for converting A main function that tests the conversion function with 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)) print(repToDecimal('10', 8)) In convert.py, define a function named repToDecimal that expects two arguments, a string, and an integer. The 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 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 4 def main(): with each key should be the integer that the digit represents. (The letter A associates with the integer "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 9. digit to uppercase, look up its value in the table, and 10 use this value in the computation.
In Chapter 4, we developed an algorithm for converting A main function that tests the conversion function with 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)) print(repToDecimal('10', 8)) In convert.py, define a function named repToDecimal that expects two arguments, a string, and an integer. The 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 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 4 def main(): with each key should be the integer that the digit represents. (The letter A associates with the integer "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 9. digit to uppercase, look up its value in the table, and 10 use this value in the computation.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
python coding
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 2 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education