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
You are asked to provide a list of security groups a user is a member of. You write a script to pull the data from Active Direct
Whitepunk [10]

Answer:

I have no clue. I wish I could help though.

Explanation:

Sorry

7 0
3 years ago
fill down feature on a formula and you need to keep a cell reference the same which one will allow you to keep the same cell ref
dedylja [7]
A dollar sign after both the letter and the number for each cell reference you want to keep the same will keep it the same when using the fill down/across function.
6 0
3 years ago
Name the tools in plant propagation.<br>Q<br>18.<br>16.<br>17.<br>19.<br>20.<br>please po asap​
Agata [3.3K]
16. Branch or tree cutter
17.paint tape
18. Knife
19. Pots
20. Waterer
6 0
2 years ago
Mr. Lee wants to show his class a presentation. Which device will display an enlarged view of his presentation?
Gnesinka [82]
A projector would make his presentation bigger.<span />
3 0
3 years ago
What is the full form of w3c
Xelga [282]
The World Wide Web Consortium, which <span>is an international community where organizations, employees</span><span> and the general public work together to develop Web standards.</span>
7 0
3 years ago
Other questions:
  • How many shared keys are required for a company of 70 employees who all need to communicate securely with each other?
    13·1 answer
  • A(n) ________ file contains data that has been encoded as text, using one of the computer's encoding schemes.
    14·2 answers
  • By default, windows does not display ____________________ in windows explorer.
    8·1 answer
  • How did mechanical clocks assist in completing work? How was work done previously?
    12·1 answer
  • A hardware compatibility list recommends striping with double parity as storage for an application. In a test environment, a tec
    13·1 answer
  • Write a script that checks to see if at least one argument has been given on the command line and tests whether the argument is
    5·1 answer
  • Write a program with 2 separate functions which compute the GCD (Greatest Common Denominator) and the LCM (Lowest Common Multipl
    9·1 answer
  • Drag each tile to the correct box.
    9·2 answers
  • The courts can adjust the penalties in lawsuits to reflect the fact that infringements may be _____.
    5·2 answers
  • What are the main differences between openldap and microsoft's active directory (ad)? check all that apply
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!