1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
hodyreva [135]
3 years ago
8

Write a Python program that translates a binary number of n bits to a decimal number. Your program should first ask the user the

length of the binary number (how many bits). Using that information, ask the user to provide each bit from lowest to highest. Once the user has entered all the bit values for the binary number, report back the decimal value. Hint: You should use the mechanism to convert binary to decimal in earlier lectures. Note: Your program should not use any functions or methods from any library.

Computers and Technology
1 answer:
KonstantinChe [14]3 years ago
3 0

Answer:

Follows are the code to this question:

n= int(input("please enter number of bits, which want to convert for binary to decimal numbers: "))

p= 1#defining variable p for calculate power

d= 0#defining variable d for calculate decimal value

for i in range(n):#defining for loop for input bits value

   b= int(input("Enter the bit value from lowest to highest: "))#input value in b

   if b==1:#defining if block that check input is 1 value

       d=d+p#calculating decimal value

   p=p* 2#calculating power

print("The converted decimal number is:",d)#print value

Output:

please find the attached file.

Explanation:

In the above-given code, n variable is defined, which takes the number of bits value which you want to convert into a decimal value.

In the next step, "d and p" variable is defined that calculates the power and decimal number and store its value respectively, in this step, a for loop is used that uses the "b" variable for inputs bits value into lowest to the highest form, and use the if block.

In this block, it checks if the input value is one then it calculates its power and store its value into the "d" variable and use the print method to print its value.  

You might be interested in
Write a program that asks the user for three strings.
Varvara68 [4.7K]

Answer:

good luck djfjjdndnfjfjjfjfdsadd

5 0
3 years ago
Countries need to engage in trade of natural resources because of distribution in the earth. For instance, countries such as Sau
maks197457 [2]
Water is a scarcity in this area
4 0
3 years ago
What is the purpose of a report?
Tanzania [10]
C to organize data in a table
4 0
3 years ago
PLS HELP ASAP ILL GIVE BRAINLKEST PLS THANKS 20 POINTS
OLga [1]

Answer:

#1?

Explanation:

Might be wrong..

5 0
2 years ago
Read 2 more answers
Which of the following is most likely to own the data resulting from a research project?
fomenos

Answer:

Option C i.e., ODS/Data warehouse is the correct answer.

Explanation:

The following option is correct because ODS/Data warehouse owns that resulting data from that project which is related to research. ODS transfer the data of the database to the data warehouses before processing that data or information in the database which is collected from the different-different sources

4 0
3 years ago
Other questions:
  • In procedural programming, where does the flow of control usually route from the main function?
    8·1 answer
  • The system administrator in your office quits unexpectedly in the middle of the day. It's quickly apparent that he changed the s
    10·1 answer
  • The purpose of hazard lights is to
    7·2 answers
  • What is the main storage device where the computer stores data?
    15·1 answer
  • Why are high-quality transformers wound with large diameter wire?
    8·1 answer
  • What is a text designed for editing and authoring code is<br> A code editor <br> B
    9·1 answer
  • How can the function anotherFunc2 change the contents of the second element of t?
    5·1 answer
  • mapa mental con la explicación de que medios de comunicación y redes sociales intervienen en la construcción de tu identidad​
    10·1 answer
  • 6.16 LAB: Find largest number (EO) Write a method, findMax(), that repeatedly reads in integers until a negative integer is read
    9·1 answer
  • Write a function that reads from a file the name and the weight of each person in pounds and calculates the equivalent weight in
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!