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
ArbitrLikvidat [17]
3 years ago
14

Write function d2x() that takes as input a nonnegative integer n (in the standard decimal representation) and an integer x betwe

en 2 and 9 and returns a string of digits that represents the base-x representation of n.
Computers and Technology
1 answer:
Rufina [12.5K]3 years ago
4 0

Answer:

The function in Python is as follows:

def d2x(d, x):

   if d > 1 and x>1 and x<=9:

       output = ""

       while (d > 0):

           output+= str(d % x)

           d = int(d / x)

       output = output[::-1]

       return output

   else:

       return "Number/Base is out of range"

Explanation:

This defines the function

def d2x(d, x):

This checks if base and range are within range i.e. d must be positive and x between 2 and 9 (inclusive)

   if d >= 1 and x>1 and x<=9:

This initializes the output string

       output = ""

This loop is repeated until d is 0

       while (d > 0):

This gets the remainder of d/x and saves the result in output

           output+= str(d % x)

This gets the quotient of d/x

           d = int(d / x) ----- The loop ends here

This reverses the output string

       output = output[::-1]

This returns the output string

       return output

The else statement if d or x is out of range

<em>    else:</em>

<em>        return "Number/Base is out of range"</em>

<em />

You might be interested in
Discuss how advertising on the Web affects search results and the ethical dilemmas associated with it.
Rus_ich [418]
Lag and loops because some ads are programmed  to work that way. 
idk im not a professional
6 0
3 years ago
What does it mean when someone silences notifications?.
grandymaker [24]

Answer:

Silencing notifications does not alert someone when the notification comes in. It is silent. These settings were invented to help avoid distractions. The notifications still come in just quietly without an alert and can be checked at any time. Lots of people silence notifcations at night, while sleeping, while studying, etc.

Explanation:

4 0
2 years ago
A comma is also called a statement terminator. A. True B. False
aleksandrvk [35]

Answer:

The answer is False

Explanation:

A comma is also called a statement terminator. A. True B. False

The answer is False

Comma is used to separate individiual values or data types

variables.

A semi-colon (;) at end of a statement is called terminator.

8 0
3 years ago
You must. place a child in a federally approved child restraint device. if the child is
abruzzese [7]
You must place a child in a federally approved child restraint device if the child is three years and under. 
5 0
4 years ago
Read 2 more answers
Elements of a job application and résumé, like dates and addresses, do not have to be accurate.
sammy [17]

Answer: False

Explanation:

The elements on a Resume gives information about the owner of the resume, in a situation where those elements are false, the audience becomes misinformed.

I hope this helps.

7 0
3 years ago
Other questions:
  • How many times is "Alert" displayed in the following loop? for (int k =0; k&lt;= 100; k++) cout &lt;&lt; "Alert"; O 101 0 1 oo О
    7·1 answer
  • What temporarily holds programs and date while the computer is on and allows the computer to access that information randomly?
    12·1 answer
  • Which spreadsheet operation does a look function perform?
    5·1 answer
  • The software application associated with a specific file type is called a(n) __________ application.
    12·1 answer
  • Is sprint having problems today
    11·1 answer
  • A measuring cylinder is used to measure the volume of an irregular<br>solid object.​
    5·1 answer
  • True or False: Wikipedia is a reliable source. ​
    5·2 answers
  • Consider the following code:
    13·1 answer
  • In binary, the second digit from the right is multiplied by the first power of two, and the _____ digit from the right is multip
    10·2 answers
  • Gavin is making a new logo for his business. He uses drawing software to create a unique. Which file format does he use to creat
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!