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
Show that ALLDFA is in <img src="https://tex.z-dn.net/?f=%5Cmathrm%7BP%7D" id="TexFormula1" title="\mathrm{P}" alt="\mathrm{P}"
Alexandra [31]

Answer:

Hypothesis testing is a vital process in inferential statistics where the goal is to use sample data to draw conclusions about an entire population. In the testing process, you use significance levels and p-values to determine whether the test results are statistically significant.

Explanation:

yup it is write

3 0
1 year ago
Please helpppppppppppppppppp please I’m stuck!
Vinvika [58]

do u know thw muffin man

3 0
3 years ago
A band wants to know what their most popular CD is so that they can have more copies made to sell. Which statistical measurement
Bad White [126]

This would be Ordinal measurement.

8 0
3 years ago
Read 2 more answers
Declaring a variable in the method’s body with the same name as a parameter variable in the method header is ___________.
icang [17]

Answer:

a. a syntax error

Explanation:

When the same variable name is repeated in the parameter set and the method body, it will result in a syntax error. This is because the variable in the parameter has a local scope within the method body. Now if we declare another variable with the same name in the method body, it will result in redefinition of the variable and violate the uniqueness principle of variable names in the method code. This will give rise to syntax error.

8 0
3 years ago
What are the three fundamental principals of mnemonics? <br><br>HELP FASTTT!
muminat

Answer:

The three fundamental principles underlying the use of mnemonics are imagination, association, and location.

Explanation:

8 0
3 years ago
Other questions:
  • Create a class named BaseballGame that contains data fields for two team names and scores for each team in each of nine innings.
    12·1 answer
  • What is the top folder of the file tree called
    5·2 answers
  • A document with a(n) ____ guarantees that the document was indeed sent by a specific individual and that it hasn t been tampered
    10·1 answer
  • In which job role would a course in 3D modeling help with professional career prospects?
    9·2 answers
  • What is variable declaration in java ​
    6·2 answers
  • The CMOS battery located on a computer's motherboard allows for maintaining the correct time and date information stored in CMOS
    7·1 answer
  • One of the most common uses of spreadsheet are
    8·1 answer
  • [This is on Edhesive (coding and programming)]
    8·2 answers
  • Write a function solution that, given an array A consisting of N integers, returns the number of fragements of A whose sum equal
    9·1 answer
  • Besides a soho router, which of these devices is a network printer most likely to be connected to? a. router b. server c. workst
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!