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
iren2701 [21]
4 years ago
12

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 modulo 2 (remainder is either 0 or 1) Assign x with x divided by 2
Computers and Technology
1 answer:
Mashcka [7]4 years ago
6 0

Answer:

Following are the code to this question:

def binarynumber(num):#defining a method binarynumber that accepts a parameter num

   x=""#defining a string variable x

   if (num!=0):#defining if condition to check number not equal to 0

       while (num>=1):#defining a loop that check value is grater then equal to one

           if (num %2==0):#defining if condition to check num is even

               x=x+"0" #add string value 0 in num variable

               num=num/2 #divide the value by 2

           else:#defining else block

               x=x+"1"#add string value 1 in num variable

               num=(num-1)/2#first subtract 1 into num variable then divide the value by 2

   else:

       x="0"#assign string value 0 in num variable  

   return "".join(reversed(x))#return value

num = int (input ("Enter any number: "))#defining num variable that input the integer value

print (binarynumber(num))#using print method to call method binarynumber with passing num parameter

Output:

Enter any number: 12

1100

Explanation:

  • In the above python code a method "binarynumber" is declared, in which the "num" variable passes as the parameter inside the method a string variable "x" is declared that stores all converted values.
  • Inside the method and if the block is declared that checks number value is not equal to 0 if this condition is false then it will add string value and reverse its value.
  • Or if the condition is true it defines a while loop that calculates the given number binary digits and returns its value.
  • At the last step, the num variable is declared that inputs the integer value from the user end and calls the method by using the print method.    
You might be interested in
Competition between individuals in a population is due to (2 points)
madam [21]
Competition between individuals in a population is due to (2 points)
limited resources
5 0
4 years ago
What is JavaScript? JavaScript is a _____ language.
disa [49]

Answer: dynamic computer language

Explanation:

JavaScript is a dynamic computer language. Hope this helps! (•‿•)

5 0
3 years ago
Read 2 more answers
Where's the space key again <br> Sorry I forgot <br> I'm so inbarest sorry <br> In my computer
Kipish [7]
The space key is the longest key on the bottom of the keyboard

8 0
4 years ago
How are radio waves used on Earth?
kicyunya [14]

Uses of Radio Waves : The prime purpose of radio is to convey information from one place to another through the intervening media (i.e., air, space, nonconducting materials) without wires. Besides being used for transmitting sound and television signals, radio is used for the transmission of data in coded form.

8 0
3 years ago
Describe how people can work in collaboration with technology to create a better world in 200 words or less.
sweet [91]

Answer:

In today life collaboration is most important because two people knowledge can do better things according to their innovation

Explanation:

mark me brainliest ❤

4 0
3 years ago
Other questions:
  • 7. Write a program in C to display the string "ARRAY" in the following format : A AR ARR ARRA ARRAY
    5·1 answer
  • What layer uses the UDP protocol
    6·1 answer
  • How many bytes of information can be stored on a hard drive?
    7·1 answer
  • You csn access various sites on the www by using hyperlinks or by
    7·1 answer
  • Templates contain common layout and formatting that can save you time by not having to recreate documents from scratch. True or
    10·1 answer
  • Which command will display each line in the text file based on the alphabet?
    10·1 answer
  • A collection of code makes up which of the following?
    14·2 answers
  • in an advertisement is made of a wireless keyboard and a mouse.Name two commonly used methods of connecting devices wirelessly​
    11·1 answer
  • &lt;BUTTON TYPE="BUTTON" VALUE="SUBMIT"&gt;SUBMIT YOUR FORM&lt;/BUTTON&gt;
    7·1 answer
  • Fill in the blank with the correct response.<br> A _<br> is an unknown network.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!