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
How many times is the second for loop going to loop in this block of code? Write your answer in numeric form in the box provided
pantera1 [17]

Explanation:

The second for loop does 1 of 4 iterations for every 1 of 5 iterations of the parent loop. meaning it is 4 x 5 which is 20.

8 0
2 years ago
Which method of deleting files can be used in windows xp and vista?
Makovka662 [10]
The correct answer is C.

4 0
2 years ago
a user reports that his dot matrix printer is printing dark and clear on the left of the paper but that the print is very light
yarga [219]

Answer:

Correctly position the platen of the printer to hold the paper in place.

Explanation:

Since the dot matrix printer is printing dark and clear on the left of the paper but very light on the right side of the paper, it is possible that the paper is not being held properly. So adjusting the platen will hold the paper properly and hence uniform prints on the paper.

Note: Dot matrix printers are printers that print closely related dots to form require texts (shapes) by striking some pins against an ink ribbon.

Some of the parts of these printers are; power supply, carriage assembly, Paper sensor, ribbon, platen and pins.

4 0
2 years ago
Which quality of service (QoS) mechanism provided by the network does real-time transport protocol (RTP) rely on to guarantee a
Radda [10]

Answer:

The real-time transport protocol (RTP) carries the audio and video data for streaming and uses the real-time control Protocol to analyse the quality of service and synchronisation. The RTP uses the user datagram protocol ( UDP) to transmit media data and has a recommended Voice over IP configuration.

Explanation:

RTP is a network protocol used alongside RTCP to transmit video and audio file over IP networks and to synchronise and maintain its quality of service.

8 0
3 years ago
What is the main difference between cell phone and mobile phone?
vitfil [10]

Answer:

A Cell Phone is, therefore, a mobile phone that works utilizing radio cells, which is an area of radio coverage. Cell phones can typically be used while moving from one cell to another without losing coverage or dropping the connection. Satellite phones are not cell phones, although they are mobile phones.

Explanation:

8 0
2 years ago
Read 2 more answers
Other questions:
  • For any element in keysList with a value greater than 50, print the corresponding value in itemsList, followed by a space. Ex: I
    8·1 answer
  • That is Entrepreneur ? ?<br>​
    8·1 answer
  • As you apply to college when should you apply for financial aid
    9·1 answer
  • What is the smallest unit of data on the hard drive?
    5·1 answer
  • Henry, a graphic artist, wants to create posters. Which software should Henry use for this purpose?
    13·1 answer
  • One software license model allows software to be freely distributed, downloaded, and installed without paying a license fee but
    15·1 answer
  • What is the Purpose and function of the Global Positioning System (GPS)?
    7·1 answer
  • The blue section of the following Venn diagram could represent which of the following Boolean statements?
    14·1 answer
  • A task-oriented leader is ideal for a creative workplace.
    8·2 answers
  • Hey everyone please let my friends answer please?????? .
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!