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
Pro and Cons of Artificial Intelligence in Art <br><br> You must have 3 statements in each
Anni [7]

Answer:

The answer is below

Explanation:

Aritifiaicla intelligence in art is an artwork created by the application of artificial intelligence software.

Some of the pros of artificial intelligence in the art are:

1. It creates a new and improved interface, specifically in graphic design such as virtual reality and 3D printing

2. It creates and mixes the artistic ideas properly, such as mixing of different instruments in music to creates a new sound

3. It establishes graphical and visual display with no blemishes o,r error when applied accordingly, such as AUTOCAD

The cons of artificial intelligence in art are:

1. Artificial Intelligence lacks emotional sense. Hence it is challenging to display artistic elements that portray genuine emotions

2. It lacks creativity. Unlike humans, artificial intelligence is not as creative as humans when it comes to words or sentence constructions in an artistic sense.

3. It doesn't apply experience to its productions. Arts can be improved with more understanding of what is happening in the society or environment; artificial intelligence cannot translate its experience into arts formation.

6 0
3 years ago
Force field meaning in science fiction
expeople1 [14]
In science fiction, a force field is a defensive barrier made up of energy. They are used to protect, people, an area, animals, etc from an attack or a destructive impact.
5 0
3 years ago
How to use 2 tabs at once on my Lenovo yoga book?​
svp [43]
To turn on Multi-window: Method 1: Swipe up from the bottom of Home screen to show Bottom switch, touch Multi-wins. Method 2: Tap Settings on Home screen, tap Multi-window, check Multi-window on the right.
3 0
3 years ago
The algorithm ____ is used to find the elements in one range of elements that do not appear in another range of elements.
Musya8 [376]

Answer:

A. set_union

Explanation:

The algorithm set_union is used to find the elements in one range of elements that do not appear in another range of elements.

4 0
3 years ago
What is one problem caused by spending too much time studying at your computer? A. It increases stress and negatively affects yo
nignag [31]

Answer:

A - It increases stress and negatively affects your sleep.

Hope that helps. x

4 0
3 years ago
Other questions:
  • A DSLR camera is made up of two parts. They are
    13·2 answers
  • Maria is comparing her history project's second-place award to her classmate's first-place award. She starts planning how to win
    6·2 answers
  • How did the invention of the printing press lead eventually to an increase in the diversity of religious expression?
    7·1 answer
  • How do emotions affect purchasing decisions?
    6·1 answer
  • To color the h2 heading, what tag would you use?
    6·1 answer
  • The rules of right-of-way<br> Pedestrians, bicyclists, and skateboarders<br> when they use the road.
    12·1 answer
  • The first numerical control machine tool was demonstrated in 1952 in the United States at the Massachusetts Institute of Technol
    14·1 answer
  • What does it mean to say that data in an Excel table is “dynamically linked” to a chart? What are the advantages of this feature
    5·1 answer
  • the increase and decrease font button and the change text colour button (as shown in the picture )are include in which group ?​
    6·1 answer
  • the application you attempted to authenticate to is not authorized to use cas. contact your cas administrator to learn how you m
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!