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
If you find yourself boxed in by a vehicle on your left or right _____________
Zepler [3.9K]

Answer: A. speed up or slow down briefly

Explanation:

put that and then i saw someone said b and it was wrong and i got mad because it was the only answer i got wrong. but it’s a

4 0
3 years ago
Read 2 more answers
Less than 40 percent of teens have used marijuana within the past year. True or false?
fgiga [73]
That is true. I hope this helps
6 0
2 years ago
When selecting a color scheme for a project which two things should you consider?
Vsevolod [243]

colorfulness and depending on your teacher pick colors that will go together on the project

6 0
3 years ago
Who benefits the most from billing by the second for cloud resources, such as virtual machines?.
scoundrel [369]

Clients that run numerous virtual machines.

<h3>What is a virtual machine?</h3>
  • A virtual machine is the virtualization or emulation of a computer system in computing.
  • The functionality of a physical computer is provided by virtual machines, which are built on computer architectures.
  • Their use may necessitate specialized hardware, software, or a combination of both.
  • Virtual machines' primary function is the simultaneous operation of several operating systems on a single piece of hardware.
  • Without virtualization, running two different physical units would be necessary to run different operating systems, such as Windows and Linux.
  • Through the use of virtualization technologies, virtual machines are made possible.
  • Multiple virtual machines (VMs) can run on a single machine thanks to virtualization, which simulates virtual hardware using software.
  • The real machine is referred to as the host, and any virtual machines running on it as the guests.

To learn more about virtual machines, refer to:

brainly.com/question/27961159

#SPJ4

7 0
1 year ago
How many owners does a sole proprietorship have?
never [62]
The sole proprietorship it is the simplist business form under which one can operate a business. the answer is one.
8 0
3 years ago
Other questions:
  • PLEASEEE HELPPPP me
    13·1 answer
  • In Word, a red wavy underline indicates a/an
    15·1 answer
  • Which code will allow Joe to print Coding is fun. on the screen? print("Coding is fun.") print(Coding is fun.) print = (Coding i
    10·2 answers
  • Justin has started a lawn mowing business in his neighborhood. He is running a weed-pulling special this month. What is the most
    8·2 answers
  • 2:3:5<br>_ _ _<br>3 2 8<br><br><br><br>find ratio​
    5·1 answer
  • int temp; temp = 180; if ( temp &gt; 90 ) { System.out.println( "This porridge is too hot." ); // cool down temp = temp – ( temp
    9·1 answer
  • Label provides the code that executes if no case label is matched ​
    6·1 answer
  • I need help!!!! 1.04
    9·1 answer
  • HEPME <br> ZOOM<br> IN <br> STOP<br> GIVIJG<br> ME <br> LINKS <br> !!
    9·1 answer
  • Please describe the role of games in modern society!
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!