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]
3 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]3 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
What natural resources products are discussed in the article? Are they renewable or nonrenewable?
Alex

Where is the article

4 0
3 years ago
Read 2 more answers
A developer writes a SOQL query to find child records for a specific parent. How many levels can be returned in a single query.
blagie [28]
The correct answer to this question is A. One level or record an be returned in a single query when a developer writes a SOQL query to find child records for a specific parent.
4 0
3 years ago
Do applications need to exchange udp control messages before exchanging data
Molodets [167]

The answer is NO.

Thats what makes UDP connectionless. Aclient that is going to send a UDP message to the server just sends it.The server does not know it is coming untill it arrives .When a server recieves a UDP message it gets the source address/port and the data.

7 0
3 years ago
P*********** is considered a serious social problem justify this statement​
vredina [299]

Answer:

I think it's not a social problem but they are doing that by their own choice . but if the girls are forced to do that is the social problem

7 0
2 years ago
Read 2 more answers
The following are a set of named spreadsheets with the indicated column headings. Use these spreadsheets to answer exercises 1.3
Dovator [93]

Answer:

There are five work sheets in this excel file, they are equipment, company, company, person and computer. Excel worksheets are made up of cells, with the columns labelled alphabetically and the rows numbered.

Explanation:

The columns of a worksheet is called a field while row are called records. They are used to locate a cell in the worksheet. There are so many statistical, mathematical and engineering functions in excel. It is used to display the analysis of data.

7 0
3 years ago
Other questions:
  • Which of the following is not one of DBA's tasks?
    14·1 answer
  • Write an expression to print each price in stock_prices. Sample output with inputs: 34.62 76.30 85.05
    9·1 answer
  • ___MSDS provides information on how to handle, store, discard and care for potentially hazardous chemicals. true or false?​
    5·1 answer
  • Pda bkhhksejc pnwjoynelp dwo xaaj ajykzaz ywj ukq zaykza ep???<br><br><br> The Key Value is 22
    12·1 answer
  • Which of the following should you consider when
    5·1 answer
  • host b is sending an email intented for the user on host a to the mail server what protocol is being used to send the message
    10·1 answer
  • Someone help meeeeeeeee plz.......................
    11·2 answers
  • Plz hurry it’s timed
    5·1 answer
  • _____moves the head to proper track
    13·2 answers
  • Lesson 2.7 Code Practice #2
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!