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
A stack is initially empty, then the following commands are performed: push 5, push 7, pop, push 10, push 5, pop, which of the f
MatroZZZ [7]

Answer:

d

Explanation:

6 0
3 years ago
Company ABC has always used passwords to protect the highly confidential information in their company. Recently, someone who was
Leno4ka [110]
Company ABC should use passwords but also have them use a code so that not just anyone can get in. Kinda like facebook.
3 0
3 years ago
Edhesive 4.3 code practice question 2
Arturiano [62]
Sos shacahacwhaveusbsusvs js

8 0
3 years ago
How many conditions are needed in a while loop that should run until a user guesses the correct number or until they have made f
Sonja [21]
<h2>[] Hello! []</h2>

Answer:

2

Explanation:

MS Coding 1 A ED

---------------------------------------------------------------------------------------

  • I hope this helped
  • Brainilest appreciated!
7 0
3 years ago
when water is poured into a styrofoam cup, nothing happens. the water stays in the cup and it can be used for drinking. however,
KengaRu [80]

The backside of the cup disappears and the fuel pours out due to the fact styrofoam is a trading name for polystyrene (PS) foams, Gasoline is crafted from a mixture of hydrocarbons, so it dissolves PS, generating a viscose paste.

Gasoline is crafted from a combination of volatile, flammable liquid hydrocarbons derived from petroleum and used as gas for internal-combustion engines. It is likewise used as a solvent for oils and fats. Gasoline is a form of gas crafted from crude oil and different petroleum liquids. Gasoline is mostly used as an engine gas in vehicles.

Learn more about gasoline at brainly.com/question/28762820

#SPJ4

3 0
2 years ago
Other questions:
  • You have decided to remove a recently installed feature which method can you use to remove this feature
    13·1 answer
  • GUI allows users to communicate with a device and see what they are doing onscreen.
    9·1 answer
  • To secure the company website, the webmaster suggests that the company purchase a secure certificate to encrypt all communicatio
    5·1 answer
  • i know this not school related but my grandmothers RCA RCT6272W23 tablet is saying type password to decrypt storage and i dont k
    5·1 answer
  • I know how to design it but I’m confused as to how to write a function code based on the info provided.
    10·1 answer
  • What does social protocol means in network?
    9·1 answer
  • Which of the following is a strategy used to enhance communication in a presentation?
    14·1 answer
  • The process of bringing data or a file from one program to another is called
    5·2 answers
  • If you hard working right now go to this EASY question
    9·2 answers
  • You are developing a Website that is going to be viewed extensively on smartphones and tablets. Which of the following should yo
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!