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
vivado [14]
3 years ago
12

Write a program that asks the user to enter a positive integer that represents a number in the decimal system and then displays

the binary representation of the number. Your solution must include at least the following function: decimalToBinary(number): a recursive function that takes a positive integer number (in decimal) as its parameter and returns a string with it's binary representation. g
Computers and Technology
1 answer:
Maru [420]3 years ago
3 0

Answer:

In Python:

def decimalToBinary(num):

   if num == 0:

       return 0

   else:

       return(num%2 + 10*decimalToBinary(int(num//2)))

       

decimal_number = int(input("Decimal Number: "))

print("Decimal: "+str(decimalToBinary(decimal_number)))

Explanation:

This defines the function

def decimalToBinary(num):

If num is 0, this returns 0

<em>    if num == 0: </em>

<em>        return 0 </em>

If otherwise

   else:

num is divided by 2, the remainder is saved and the result is recursively passed to the function; this is done until the binary representation is gotten

       return(num%2 + 10*decimalToBinary(int(num//2)))

       

The main begins here.

This prompts the user for decimal number

decimal_number = int(input("Decimal Number: "))

This calls the function and prints the binary representation

print("Decimal: "+str(decimalToBinary(decimal_number)))

You might be interested in
Can anyone tell me what's wrong with my pc. When I turn it on it lights up the ram, motherboard, and fans. The cooler and case f
Mice21 [21]

1 or 2 ways I can try to figure out and see what is causing your computer to do this. 1 when was the last time you shut off  OR was doing on the computer? If your problem gets fixed make sure you close all running apps so the apps don't update while your computer is shutdown. 2 did you or something unplug the cables? Or maybe a virus caused something. Try to unplug every cable and wait about 5-10 minutes and if your computer is still not working, I would advise contacting an administrator.

Hope this helped.

6 0
3 years ago
What is the first step in creating a maintenance ?
tankabanditka [31]
The first step would be knowing the manufacturer s recommended schedule for maintenance
7 0
3 years ago
Which of the following is the core communications protocol for the internet? telnet ftp tcp/ip ssl
inna [77]
Tcp/ip is the core communication protocol for the internet
4 0
3 years ago
What is a good principle to implement when you find yourself attempting to
Maurinko [17]

its less is more A

to much could make it really bad

5 0
3 years ago
What item is at the front of the list after these statements are executed?
Veseljchak [2.6K]

Answer:

A.Sam.

Explanation:

We are using Deque interface which is sub type of  Queue interface. Deque supports insertion and deletion from both ends front and end.So it can be used as a queue and stack also.

In this question we have inserted Jack at the front first.Then Rudy at the back then larry also at the tail.Now we have added sam at the front then nothing is added to the front.So the answer is Sam.

7 0
3 years ago
Other questions:
  • Olivia needs to get permission to use a graph of data gathered by a trade association she plans to include the graph in a report
    10·2 answers
  • Encryption relies on the use of _________to ensure that information is readable only by the intended recipient.
    5·1 answer
  • You have been hired to set up a network for XYZ Enterprises. What factors will you consider to determine the type of network nee
    7·2 answers
  • Assume that play_list refers to a non-empty list, and that all its elements are integers. Write a statement that associates a ne
    7·1 answer
  • Prompt the user to input an integer, a double, a character, and a string, storing each into separate variables. Then, output tho
    9·1 answer
  • Write a program that tells what coins to give out for any amount of change from 1
    6·1 answer
  • Type 1 hypervisor:
    10·1 answer
  • That's my email address​
    14·1 answer
  • explain why you can determine machine epsilon on a computer using IEEE double precision and the IEEE Rounding to Nearest Rule by
    7·1 answer
  • HELP 100 points
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!