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
icon
Related questions
Question

python coding

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.
Transcribed Image 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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Introduction to computer system
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
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education