Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions 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.
expand button
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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education