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))

Answers: 1

Another question on Computers and Technology

Computers and Technology, 01.02.2019 19:17
Aisha has finished working on a word processing document that contains 15 pages. she has added some special elements in the first three pages, page 9 and 10, and page 15 from the document. she wants to print only these pages to see how they look. which option is the correct way to represent (in the print dialog box) the pages that aisha wants to print?
Answers: 3
Computers and Technology, 31.01.2019 18:10
You have a large, late-model pick-up truck with a rear seat. the pick-up truck weighs 6,500 pounds. the florida seat belt law
Answers: 1
Computers and Technology, 30.01.2019 18:22
Budgets you to do all of the following expect a) send frivolously b) avoid over spending c) gain financial independence d) examine your priorities and goals
Answers: 2
Computers and Technology, 23.01.2019 22:48
Intellectual property rights are exclusive rights that protect both the created and the creation. ipr offers exclusively what benefits to the person or people covered by it
Answers: 3
You know the right answer?

programming exercise 5.5

in convert. py, define a function named re...
Questions on the website: 6669507