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
Yakvenalex [24]
3 years ago
10

Function Name: d2x Parameters: int, int Returns: string Description: Write function, d2x, that takes as input a nonnegative inte

ger v (in the standard decimal representation) and an integer x between 2 and 9 and returns a string of digits that represents the base-x representation of v. To convert a value, v from base-10 to base-x, v is divided by x successively until the quotient of v divided by x is 0. On each successive division, the remainder is the new most significant digit in your answer. For the function call, d2x(10, 2), should return '1010':

Computers and Technology
1 answer:
Marina CMI [18]3 years ago
6 0

Answer:

I am writing a Python program. Let me know if you want the program in some other programming language.

#definition of function d2x which takes two parameters v: which is a non #negative integer and x which is an integer between 2 and 9. this method #returns string of digits that represents the base-x representation of v

def d2x(v,x):

   remainder = v%x  

   if v<=1:

       return str(v)

   else:

       return str(d2x(v//x,x)) + str(remainder)

 

v= int(input("Enter a non negative integer: "))

x= int(input("Enter an integer between 2 and 9: "))

print(d2x(v,x))

Explanation:

I will explain the code line by line.

def d2x(v,x) This is the definition of function d2x which takes two parameters v: which is a non negative integer and x which is an integer between 2 and 9. This method returns string of digits that represents the base-x representation of v.

Now lets take an example to understand the working of this function.

Suppose the value of v = 10 and x = 2.

remainder = v%x  takes the mod of v and x which returns the remainder of the division of v by x. So v%x = 10 % 2 = 0. So remainder = 0.

if v<=1 This if condition checks if the value of v is less than or equal to 1. This is false because v=10 and 10 is greater than 1. If v is 1 or less than return str(v)  will return the value of v as it is i.e. 10.

Since the IF condition is false so the else part will execute which has the following statement: return str(d2x(v//x,x)) + str(remainder)

This calls the d2x function recursively. Here v is divided by x successively until the quotient of v divided by x is 0. On each successive division, the remainder is the new most significant digit. In v//x, the double slash is called floor division or integer division which we use as both v and x are integers. So using recursion the above statement becomes:

str(d2x(v//x,x)) + str(remainder)

str(d2x(10//2,2) + str(0)

d2x(5,2) + (0)

Now d2x will again be called recursively to perform the division and this successive division continues until quotient of v divided by x is 0. Here str() method is used returns the result in the form of string.  So v%x is the number which is added to the end of resultant number. v//x is the recursive portion which keeps using the answer of the previous binary number. This means 10 in base 2 calls convert(5,2), then adds 0 at the end. So when v//x=5 and v%x=0 So the answer is 1010.

At the end v= int(input("Enter a non negative integer: "))

x= int(input("Enter an integer between 2 and 9: "))  these two statement wills take integer input from user and print(d2x(v,x)) calls d2x method and print the result.

You might be interested in
Write pseudocode instructions to carry out each of the following computational operations:1. Determine the area of a triangle gi
Zinaida [17]

Answer:

Hi there! The question is checking your knowledge on Pseudocode. Pseudocode is a high level solution written in plain English to outline the steps needed for the program to work correctly. An implementation for the different parts of the question is written below.

Explanation:

1. Determine the area of a triangle

  declare formula for area calculation of triangle as ½ * (base * height)

  validate input parameters “base” and “height”

  apply formula and return result

2. Compute the interest earned Prompt user for input 2

   declare formula for interest calculation as annual interest rate * term *     starting account balance

   validate input parameters “interest_rate” and “starting_account_balance ”

   apply formula and return result as final balance at the end of the year as the interest earned + starting balance.

3. Determine the flying time between two cities given the mileage M between them and the average speed of the airplane.

   declare formula for time calculation of triangle as time = distance / speed

   validate input parameters for mileage “M” and speed “S”

   apply formula and return result

7 0
3 years ago
1.
saul85 [17]

Answer:

1. Speakers

2. Software

3. C.P.U

4. ROM

5. Hard drive

6. RAM

7 0
2 years ago
Did this technological advancement take away or create jobs? Overall, what was the contribution of this technological advancemen
mars1129 [50]
It took away jobs and made day to day tasks easier
3 0
3 years ago
Q10: Putting it all together (0.75 points) Here, we'll update the values in dictionary, storing the output in a dictionary calle
Molodets [167]

Answer:

# Code in Python

dictionary={'A':1,'B':2,'C':3,'D':4}

other_dictionary={}

for keys in dictionary:

if dictionary[keys]&1==1:

temp=dictionary[keys]*dictionary[keys]-10*10

other_dictionary[keys]=temp

else:

other_dictionary[keys]=dictionary[keys]

print(other_dictionary)  

assert other_dictionary

Explanation:

  • Initialize a sample example dictionary  and other_dictionary.
  • Do a binary comparision for checking odd number .
  • Update the the value stored in the dictionary to store the squared difference of the original value and '10'.
  • For even: store the original value (from dictionary).
4 0
3 years ago
The ______ clause allows us to select only those rows in the result relation of the ____ clause that satisfy a specified predica
baherus [9]

Answer:

1. Where,

2. From

Explanation:

In SQL query language when working on a database, a user can use certain clauses to carry out some functions.

Hence, The WHERE clause allows us to select only those rows in the result relation of the FROM clause that satisfy a specified predicate.

This is because the "Where clause" selects the rows on a particular condition. While the "From clause" gives the relation which involves the operation.

5 0
2 years ago
Other questions:
  • Jail and prison officials may generally limit inmate rights when the limitations serve
    13·2 answers
  • In doing a load of clothes, a clothes drier uses 18 A of current at 240 V for 59 min. A personal computer, in contrast, uses 3.0
    7·1 answer
  • A computer that delivers requested webpages to your computer or mobile device is a(n) _________.
    9·1 answer
  • When you access the programs and documents on a computer by what way of icons is said to be employing
    6·1 answer
  • For this assignment, select one of the organizations with a prominent IT department from the Topic 1 assignment. Once identified
    11·1 answer
  • ____ Is an Internet service that allows users to send and receive short text messages In real time.
    10·1 answer
  • Monster Collector
    7·1 answer
  • Tell the story, step by step, of how your computer finds the CodeHS server,
    9·1 answer
  • I WILL MARK BRAINIEST FOR THIS!!!!!!
    11·2 answers
  • If you select one slice of pie in a pie chart, you have selected a ____
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!