Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python Programming Exercise 5.5 In convert.py , define a function named repToDecimal that expects two arguments, a string, and an integer. The second argument should

python

Programming Exercise 5.5

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, 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 actually a dictionary) is initialized before the function is defined.

For its keys, use the 10 decimal digits (all strings) and the letters A . . . F (all uppercase). The value stored with each key should be the integer that the digit represents. (The letter A associates with the integer value 10, and so on.)

The main loop of the function should convert each digit to uppercase, look up its value in the table, and use this value in the computation.

Include a main function that tests the conversion function with numbers in several bases.

An example of main and correct output is shown below:

def main(): print(repToDecimal('10', 10)) print(repToDecimal('10', 8)) print(repToDecimal('10', 2)) print(repToDecimal('10', 16)) 
10 8 2 16 

image text in transcribed

Programming Exercise 5.5 In convert.py, define a function named repToDecinal that expects two arguments, a string, and an integer. The second argument should be the base. For example, repToDecimal("10", 8) returns 8, whereas repToDecinal"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 actually a dictionary) is initialized before the function is defined. For its keys, use the 10 decimal digits (all strings) and the letters A...F (all uppercase). The value stored with each key should be the integer that the digit represents. (The letter A and so on.) associates with the integer value 10, The main loop of the function should convert each digit to uppercase, look up its value in the table, and use this value in the computation. Include a main function that tests the conversion function with numbers in several bases. An example of main and correct output is shown below def main) print(repToDecimal'10, 10)) print(repToDecimal('10', 8)) print(repToDecimal('10', 2)) print(repToDecimal('10", 16)) 10 16

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sybase Database Administrators Handbook

Authors: Brian Hitchcock

1st Edition

0133574776, 978-0133574777

More Books

Students also viewed these Databases questions