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
Sarah needs help with a presentation that she is giving the next day. What are the best ways for her to share her work to get im
Papessa [141]

Answer:

Office365 with PowerPoint Online comment accessibility.

7 0
3 years ago
Read 2 more answers
Which option is not a tab type? center tab right tab hanging tab left tab
Gala2k [10]

Answer: C

Explanation:

6 0
3 years ago
Read 2 more answers
Think about the ways new communication technologies can make certain tasks easier for
Andru [333]
Technology gives them the ability to do things that they normally couldn’t do. Like deaf people could get a cochlear implant to make them hear, people without a leg can get a prothetic leg to help them walk. Even something as simple of being colorblind, there are glasses to help them see color. It’s amazing.
3 0
3 years ago
A _____________ delivers all the files that form web pages
Alexus [3.1K]

The database of the worldwide web delivers all the files that form web pages.

<h3>What is the worldwide web?</h3>

The World Wide Web (WWW), sometimes known as the Web, is the most widely used software platform on the planet  It is an online information space where documents and other web resources can be viewed using a web browser through the Internet.  

The Internet has had a huge impact on people's lives.  It is the major means of communication on the Internet for billions of people throughout the world.

Therefore database of the worldwide web delivers all the files that form web pages.

To know more about the worldwide web follow

brainly.com/question/14715750

#SPJ4

6 0
2 years ago
Assume that someone dictates you a sequence of numbers and you need to write it down. For brevity, he dictates it as follows: fi
Basile [38]

Answer:

We have the following code in python with appropriate comments

Explanation:

line = input("Enter your line of integers: ")

# Splits at space

intList = line.split()

#initializing the count to 1

count = 1

#initializing the count to empty string

output = ''

#iterating over the list

for index, x in enumerate(intList):

 

#handling last index separately

if index == len(intList)-1:

if intList[index] == intList[index-1]:

output = output + str(count) + ' ' + str(intList[index])

else:

count = 1

output = output + str(count) + ' ' + str(intList[index])

 

#handling indexes other than the last index    

else:

 

if intList[index]==intList[index+1]:

count = count + 1 #if next integer is same, we increase the count by 1

else:

output = output + str(count) + ' ' + str(intList[index]) + ' '

count = 1

print(output)

6 0
4 years ago
Read 2 more answers
Other questions:
  • You can deselect multiple selected sheets beginning with the sheet1 tab by pressing the ____ key and clicking the sheet1 tab.
    15·1 answer
  • Alison retrieved data from a company database containing personal information on customers. When she looks at the SSN field, she
    14·1 answer
  • Greg works for an online games development company. He is not a net freak, but occasionally he visits online literature sites an
    7·1 answer
  • Hidden-surface removal is the process of:
    14·1 answer
  • Suppose you are organizing a party for a large group of your friends. Your friends are pretty opinionated, though, and you don't
    14·1 answer
  • 4.3 Code Practice<br> edhisve
    13·1 answer
  • Tightly.
    5·1 answer
  • Type the correct answer in each box. Spell all words correctly.
    12·1 answer
  • spreadsheet solution Credit Score Current Rate First Name: Mary 500 6.50% Last Name: Bell 550 6.25% Address: 123 First Street 60
    11·1 answer
  • Does putting a glue stick on your touchpad make it stop working pls help
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!