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
What is the purpose of OPPA<br>​
aivan3 [116]

Answer:

The purpose of OPPA is to make its mandatory for companies to disclose what kind of information they will acquire from their users.

Hope it helps you!!

7 0
3 years ago
What is the central unit of the computer that contains the logic circuitry and carries out the instructions of the computer's pr
weqwewe [10]
Well, it's called Central Processing Unit, or CPU.
8 0
3 years ago
A communications medium that carries a large amount of data at a fast speed is called
babymother [125]
Either Firewire, or an ethernet cable.
7 0
3 years ago
How does a hard drive work
svetlana [45]
A small hard drive typically has only one platter, but each side of it has a magnetic coating. Bigger drives have a series of platters stacked on a central spindle, with a small gap in between them. The platters rotate at up to 10,000 revolutions per minute so the read-write heads can access any part of them.
7 0
3 years ago
Countries need to engage in trade of natural resources because of distribution in the earth. For instance, countries such as Sau
maks197457 [2]
Water is a scarcity in this area
4 0
3 years ago
Other questions:
  • On other questions, how do I write my own question, without commenting on others questions? It is only allowed two, I think, the
    13·1 answer
  • What is the output of the second println statement in the main method, public class foo { int i ; static int s ; public sttic vo
    15·1 answer
  • 1.Customer service is assistance provided by a company to the people who buy or use its products or services.
    13·2 answers
  • A user is trying to delete a file located on an ntfs volume on his windows 8 computer but is unable to do so. Why is this.
    5·1 answer
  • An airline has found about 7% of its passengers request vegetarian meals. On a flight with 166 passengers the airline has 16 veg
    11·1 answer
  • How do you make the "Colorize" feature in GIMP consistent if you cannot connect the different places? Brainliest if you also exp
    12·2 answers
  • Adam is an Engineering student but has decided that he does not want to work in that field, but in the Manufacturing career clus
    11·2 answers
  • Kevin needs to get his data from a database into a text file to send to another group. He needs to _____.
    12·2 answers
  • A label control may be added to a form by double-clicking on the Label control icon in the ________ window.
    15·1 answer
  • Mechanisms that can be used to rescue accident victims
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!