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 the DML statement to query the database for the following: Output the fname, lname, total_amount_owed of the student with
Serggg [28]

Answer:

SET IDENTITY_INSERT jobs ON

INSERT INTO jobs  (job_id, job_desc, min_lvl, max_lvl)

VALUES (19, ’DBA2’, 100, 175)

SET IDENTITY_INSERT jobs OFF

Explanation:

7 0
3 years ago
What can help establish the focus and organization it relies on?
lianna [129]

Answer:

the answer is A jdififkfmtmg of g

8 0
4 years ago
The data model shows the_______structrue of database.​
Kay [80]

The data model shows the <u>rows and columns</u> structrue of database.

6 0
3 years ago
Match the risk mitigation techniques with their characteristics.
larisa86 [58]
Avoid- Failing to do certain things to eliminate the possibility of risks.
Transfer-<span>Moving the risk to another party or organization 
that is ready to share the risk financially 
or otherwise.
Accept-</span><span>Considering the negative impact involved in a 
project and carrying it out in spite of the risks.
</span>Mitigate-<span>Lowering the level of risks by making changes 
in your plan.</span>
6 0
3 years ago
If a wheel is adjustable to move caster forward is considered which type
Yuki888 [10]

Maybe axle i think so

8 0
4 years ago
Other questions:
  • Are there any tips or helpful advice for people who want to learn Photoshop?
    10·1 answer
  • 1.the following code example would print the data type of x, what data type would that be?
    12·1 answer
  • Consider the markets for monitors, USB drives, central processing units, and Microsoft’s Windows. Assume monitor manufacturers u
    7·1 answer
  • Which of the following is a potential hazard
    12·2 answers
  • Which new console should i buy Nintendo switch Xbox series x or a ps5
    14·2 answers
  • Most sources consider the ARPA-NET project the birth of computer blank<br> .
    11·2 answers
  • PLEASE HELP
    7·2 answers
  • Helllllllllppppppppppp
    9·1 answer
  • 5. Why do we need programming language?​
    13·2 answers
  • _________ in online education refer(s) to how fairly the particular needs of particular groups of students are met.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!