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
You should use the longest possible shutter speed for all firework photographs.
cluponka [151]
Im guessing false because in that time passed the picture you want to capture is changed
3 0
3 years ago
Read 2 more answers
What is the approximate boiling point
lesantik [10]
For water the approximate boiling point is 100 degrees Celsius.
<span />
4 0
3 years ago
A vehicle fails an HC emission test at idle and 2,500 rpm, and the engine has an acceleration stumble. The heated oxygen sensor
Natalija [7]

I would say a defective O2 sensor

6 0
3 years ago
What model involves the creation of data and process models during the development of an application
matrenka [14]

Answer:

Data modeling

Explanation:

Data modeling is a term used in computer or software engineering. It is a technique of creating a data model for an information system through unusual formal methods. It also involves the analysis of models during the development of an application. It is further divided into three places including:

1. Conceptual data

2. Logical data model

3. Physics data model

Hence, Data modeling is a model that involves the creation of data and process models during the development of an application

6 0
3 years ago
. Electricians will sometimes call ______ "disconnects" or a "disconnecting means."
arlik [135]

Answer: A: Switches

Explanation:

6 0
3 years ago
Other questions:
  • The section called Breaking Substitution Ciphers (p. 166) describes a "random substitution cipher," in which each letter of the
    11·1 answer
  • Write a program that uses for loops to perform the following steps: Prompt the user to input two integers: firstNum and secondNu
    15·1 answer
  • Write c++ program bmi.cpp that asks the user bmi.cpp the weight (in kilograms) and height (in meters).
    12·1 answer
  • No matter what medium connects computers on network-copper wires, fiber-optic cables, or a wireless setup; the same protocol mus
    11·1 answer
  • Which of the following is NOT part of the URL for an Internet web site?
    13·1 answer
  • highlight the possible risks and problems that should be address during the implementation of information system process
    5·1 answer
  • A10:A20 Refer to values in
    8·1 answer
  • What is the CPU's role?
    15·2 answers
  • A transistor may be used as an amplifier in an electronic circuit. <br> Select one: True False
    12·1 answer
  • This isn't an academic question, but can anyone help me change the face on my apple watch to a picture from my camera roll? I've
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!