subject

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

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 06:50, Mordred809
Type the correct answer in the box. spell all words correctly. which view of report creation allows you to customize the report before the database program creates it? creating a report in allows you to customize the report before the database program creates it. pl asap
Answers: 1
image
Computers and Technology, 22.06.2019 20:00, random286
How is the number 372 written when expanded out to place values in the base 8 (octal) number system? a. 2 x 4 + 3 x 2 + 4 x 1 b. 3 x 64 + 7 x 8 + 2 x 1 c. 3 x 8 + 7 x 7 + 2 x 6 d. 3 x 100 + 7 x 10 + 2 x 1
Answers: 1
image
Computers and Technology, 24.06.2019 04:30, NEUROPHARMACOLOGICAL
The ieee 802.11: defines standards for wireless local area network (wlan) communication protocols. identifies various computers or devices connected to a network. verifies any resource attached to another computer on a network that is different from the computer to which the user is logged on. connects multiple local area networks (lans) and wide area networks (wans).
Answers: 2
image
Computers and Technology, 24.06.2019 22:30, gabi83
To add additional commands to the quick access toolbar, a user can navigate to the view. backstage status bar design file
Answers: 2
You know the right answer?
Python

programming exercise 5.5

in convert. py, define a function named re...

Questions in other subjects:

Konu
Mathematics, 18.12.2020 08:00
Konu
Mathematics, 18.12.2020 08:00