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
Mariulka [41]
4 years ago
13

Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binar

y. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x
Computers and Technology
1 answer:
mylen [45]4 years ago
3 0

Answer:

The program to this question can be described as follows:

Program:

num= int(input('Enter a number: ')) #input value by user

st = '' #defining string variable

while num > 0: #define loop to calculte values binary number

   val= num % 2 # holding remainder (0 or 1) in val variable

   st =st+str(val) # store value in str variable

   num = num//2 #calculte quotient value

print("binary number is: ",st)

Output:

Enter a number: 5

binary number is:  101

Explanation:

Program description as follows:

Firstly the "num" variable is declared, for user input, then an "st" variable is declared, to calculates user input value binary number.

In the next step, a while loop is declared, inside the loop, another variable "Val" is declared, that holds value remainders, which is added on the "st" variable.

Outside the loop, the print method is used, that prints st variable holds value.

You might be interested in
Look at the simple circuit illustrated in the figure above. What will happen when only switch S1 is closed?
Tema [17]
If only S1 is closed, due to the diode across S3 is pointing to the right, the current cannot be flowing to the left.

So nothing will happen, the bulb is not on.
6 0
3 years ago
Read 2 more answers
Does anyone know about the progressive era?
Umnica [9.8K]

Answer: The Progressive Era was a period of widespread social activism and political reform across the United States that spanned the 1890s to the 1920s.

Explanation:

8 0
3 years ago
Read 2 more answers
What is the name of a statement written to retrieve specific data from a table?
Shkiper50 [21]
The answer is b.record
4 0
3 years ago
2. A _______
miv72 [106K]

Explanation:

A computer is an electronic device that can store and proceda

7 0
3 years ago
Insect population An insect population doubles every generation. Write a while loop that iterates numGeneration times. Inside th
yuradex [85]

Answer:

function currentPopulation = CalculatePopulation(numGeneration, initialPopulation)

    i = 1;

    currentPopulation = initialPopulation;

    while(i <= numGeneration)

         currentPopulation = 2* currentPopulation;

         i= i+1;

    end

end

Explanation:

  • Assign 1 to i as an initial loop value .
  • Assign  initialPopulation to currentPopulation  variable.
  • Run the while loop until i is less than numGeneration.
  • Inside the while loop, double the currentPopulation  variable.
  • Inside the while loop, Increment the i variable also.

6 0
3 years ago
Other questions:
  • The most popular input device of a computer is a(n) ____.
    6·1 answer
  • Define the term entity and give an example of an entity .
    10·1 answer
  • If you look at a white object through a glass of any color, it must appear to remain white.
    9·1 answer
  • Consider the unsigned decimal number 35. What is the value in hexadecimal?<br><br> 1. 3510 = ____ 16
    13·1 answer
  • To create a query string, you add a ____ immediately after a url, followed by the query string.
    15·1 answer
  • Select what's true about packet sniffers. Check All That Apply Legitimate sniffers are used for routine examination and problem
    15·1 answer
  • Describe the characteristics of a mesh network.
    13·1 answer
  • Llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll
    7·1 answer
  • B. Does “refactoring” mean that you modify the entire design iteratively? If not, what does it mean?
    7·1 answer
  • _____ is the practice of using the internet to provide healthcare without going to a doctor’s office or hospital.
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!