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
Task 2
yanalaym [24]

Answer:

If the following answer is helpful please mark as brainliest. This is the answer:

Explanation:

print("What is your name?")

name=input()

print("And where do you live", name)

location=input()

print("I've never been to", location)

5 0
1 year ago
13./ Write a java program to input an integer N and compute its factorial. Print the number and the factorial.
antoniya [11.8K]

Answer:

Código Java de forma recursiva que nos ayuda a calcular el factorial de ... El factorial de un número es la multiplicación de los número que van del ... Para expresar el factorial se suele utilizar la notación n! ... mayo 5, 2010 - 4:13 am ... un programa q de un numero dado en arabigo o romano lo imprima ya

Explanation:

Espero te sirva!!

3 0
2 years ago
Lil fun question : burgers or pizza??
Margarita [4]
Pizza. . . . . . . . . . .
6 0
2 years ago
Read 2 more answers
A certain computer has a 4meg address space. how many bits wide is this computer's address bus?
PIT_PIT [208]
22 bits






-----------------------------------
4 0
2 years ago
Query " frosty the snowman
julsineya [31]
I don't think that is a query...
5 0
3 years ago
Other questions:
  • Use the image below to answer this question.
    14·1 answer
  • The ____ button resets slide placeholders to their default position, size, and text formatting.
    11·1 answer
  • Use the _______ command to combine the selected cells and center them. merge across center across selection merge cells merge an
    7·1 answer
  • Seth is researching new developments in cancer treatments. Which suggestion would be most beneficial to making sure his search r
    14·1 answer
  • Which of these statements makes the most sense? a folder is contained within a file. a file is contained within a folder. a driv
    9·2 answers
  • List the difference between GIGO and bug ​
    15·1 answer
  • Computer programming 3
    13·1 answer
  • Which statement assigns the value 140 to the variable streetNumber in Python?
    13·1 answer
  • Which 1947 Invention paved the way for the Digital Revolution?
    12·2 answers
  • Which wireless standard runs on both the 2.4 and 5 GHz frequencies?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!