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
A company operates on two types of servers: 2 large servers (L) and 4 smaller servers (S), with a combined total of 64GB RAM. Th
kati45 [8]

Explanation:

Let the size of a large server be L, and

the size of a small server be S.

We are given two scenarios,

2L+4S = 64.............(1)

and

L+3S = 40...............(2)

We solve the equations as follows

2(2)-(1)

2L-2L +6S-4S = 2*40-64

2S = 16

so S=8 ..................(3), size of small server

substitute (3) in (2)

L+3(8) =40

L = 40-24 = 16..............size of large server

8 0
3 years ago
Match the order in which you should develop a plan:
Advocard [28]

Develop

Present

Approve

Brainliiest please?

4 0
3 years ago
How can these requirements be met? Universal Containers conduct evaluations of their sales reps using a custom object consisting
Rudik [331]

Answer:

The answer is B. Use a private sharing model granting record access using custom setting; manage field access with page layouts and field level security

Explanation:

The answer is B. Use a private sharing model granting record access using custom setting; manage field access with page layouts and field level security.

The reason the answer is B is because if access is provided through a hierarchy, it will give access to all the users at the higher manager role for the records of every executive. Also the options provided do not state clearly if Grant access using hierarchy is also checked so we cant assume that.

4 0
3 years ago
Which of the following careers is part of the Printing Technology pathway?
torisob [31]
Textile designer i think

6 0
3 years ago
What is the term for the era created by the digital revolution?
Ahat [919]
Technological innovation
8 0
3 years ago
Other questions:
  • Computers are said to use binary data because all computer data is simply a series of Os and 1s.
    10·1 answer
  • Why are specification for food processing tool,equipmentand untensils necessary?​
    8·1 answer
  • If you are inserting an address block with the Address Block dialog box and the fields do not connect automatically, what can yo
    6·2 answers
  • If an engine has four cylinders and a total of 16 valves, how many valves would each cylinder have? A. Two B. One C. Four D. Thr
    12·1 answer
  • Is there a way to earn free robux
    7·2 answers
  • A driving school uses this rule to estimate how many lessons a learner will require.
    9·1 answer
  • Draw a flowchart to find the average grade in 3 subjects
    7·1 answer
  • Rafi is developing an application to send urgent information about global health crises over the Internet to hospitals. He is wo
    6·1 answer
  • What java syntax allows me to take user input.
    11·1 answer
  • this feature offered by mutual funds allows investors to switch from one mutual fund to another within a fund families.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!