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]
2 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]2 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
The user documents are stored in _______ format.
BartSMP [9]

The user documents are stored in _______ format.

A. qvd.

B.  qvw

C.  None of the options

D.  qvs.

Answer:

B.  qvw

Explanation:

Given the options available, it can be inferred that the application the question is referring to is called QlikView which is a software application that is used for analytics explanation. This software applications saves documents created in a file extension specifically known as "QVW."

Hence, the right answer is that: in QlikView, the user documents are stored in QVW format.

8 0
3 years ago
Yolanda is making a banner for a school pep rally. She cuts fabric in the shape of a parallelogram. The angle at the bottom left
Irina18 [472]

The answer is 100°

A parallelogram is any four sided shape with two pairs of opposite parallel and equal length sides. It is safe to say that a square is a parallelogram and not the other way round.

To explain how we got to 100 degrees, I have attached an image. Based on the image attached, the opposite angles are equal. The adjacent angles are supplementary. With this in mind, the supplement of 80° will be 100°


5 0
3 years ago
Read 2 more answers
All slides in a presentation must use the same transition. True or False?
krek1111 [17]
False. you can make different slides have different transitions
7 0
3 years ago
Read 2 more answers
What is another word for microchips operating systems input methods and everything in between?
lord [1]
The answer is computer. A computer is made up of microchips (CPU and GPU), an operation system (macOS or Windows), input methods (keyboard and mouse), and other parts.
7 0
3 years ago
If you were programming a robot to respond to touch, the path might look something like this:
aniked [119]

Answer:

what

Explanation:

5 0
3 years ago
Read 2 more answers
Other questions:
  • With a _____ network connection, the computers and other devices on the network are physically connected via cabling to the netw
    10·2 answers
  • Unit testing:_________. A. provides the final certification that the system is ready to be used in a production setting. B. incl
    8·1 answer
  • In which type of attack do you get malicious code in links from seemingly reliable websites?
    14·1 answer
  • Why do most laptops have LCD rather than OLED displays, which are found on mobile devices?
    9·1 answer
  • You created the following dictionary relationships = {'Jimmy':'brother', 'Carol':'sister'}. You then executed the following code
    5·1 answer
  • Select one or more of the following: Which of these events will cause signal(s) to be generated by the kernel (the operating sys
    6·1 answer
  • Write a method that returns a version of the given array where all the 10's have been removed. The remaining elements should shi
    9·1 answer
  • What can the tab key do
    10·1 answer
  • I'm trying to move the figure a little away from, the column line and every time I move it and click ok it goes back to being be
    11·1 answer
  • What is the best description of a programming language?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!