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
Blender is used by which video game team member?
prohojiy [21]

Answer:

The 2nd one

Explanation:

6 0
3 years ago
How do Humza's videos counter hate speech and xenophobia
o-na [289]

Humza's videos counter hate speech and xenophobia as he doesn't let the negativity get to him, he tries and succeeds to make positive changes for unity.

<h3>What is xenophobia?</h3>

The fear or hate of everything that is viewed as being alien or weird is known as xenophobia. It is a manifestation of perceived conflict between an ingroup and an outgroup and may take the form of mistrust of one another's actions, a wish to have them removed, or concern over losing one's ethnic, racial, or national identity.

Simply described, xenophobia is the fear or dislike of strangers or foreigners; it manifests itself in prejudiced attitudes and behaviors and frequently ends in violence, abuse of any kind, and displays of hatred. In this case, it should be noted that he preached love and the importance of being united.

Therefore, Humza's videos counter hate speech and xenophobia as he doesn't let the negativity get to him, he tries and succeeds to make positive changes for unity.

Learn more about xenophobia on:

brainly.com/question/24366668

#SPJ1

8 0
2 years ago
How can i learn about networks
timama [110]

Answer:

1. Clients and servers—how services such as e-mail and web pages connect using networks.

2. IP addresses—how devices on a network can be found.

3. Network hubs, switches and cables—the hardware building blocks of any network.

4. Routers and firewalls—how to organize and control the flow of traffic on a network.

3 0
3 years ago
Write the CSS for an id with the following attributes: i. float to the left of the page. ii. light tan background. iii. Verdana
miss Akunina [59]

Answer:

We create a block div with an id="block" and we make the css code

Explanation:

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>bloque</title>

<link href="bloque.css" rel="stylesheet" type="text/css">  

</head>

<body>

<!--we create the div with the id="block" and a text "hello world"-->

<div id="block"> hello world </div>

 

</body>

</html>

/* CSS Document */

/* we create the CSS file, then with the same id="block" we're programming in the CSS code*/

#block{

background-color: #ECDEC9;

padding: 20px;

float: left;

font-size: 50px;

font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans",     "DejaVu Sans", "Verdana", "sans-serif";

}

4 0
4 years ago
How much RAM memory is recommended for your computer to be used as a digital darkroom?
Montano1993 [528]

1-2 GB

I had hard time finding the answer to this, but the correct answer on my test was 1-2 GB

6 0
4 years ago
Other questions:
  • The salesperson in a cell phone store is telling me that the phone I'm considering has 8GB of memory, which means I can save 10,
    13·1 answer
  • The type of meter used to test downstream digital signal quality
    12·1 answer
  • While visiting a web site during your lunch break, you see a window that states the web site will not operate properly without f
    13·1 answer
  • After a file downloads, you can do any of the following except
    13·1 answer
  • My friend Leo wants to have an emergency plan for his final exams on University of Southern Algorithmville. He has N subjects to
    9·1 answer
  • Crack the secret message: Crrp, Crrp, Crrp Zh'uh jrlqj wr wkh prrq. Li brx zdqw wr wdnh d wuls, Folpe derdug pb urfnhw vkls. (hi
    8·1 answer
  • Given the variable ip, already declared as a pointer to an integer, write the code to dynamically allocate memory for a single i
    15·1 answer
  • Explain 5 service provided by Internet​
    6·1 answer
  • Advantages against its counterpart because of its portability​
    8·1 answer
  • What types of actions exist in activity diagrams?<br>​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!