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
Edhisive 3.5 code practice
Amanda [17]

Answer:

x = int(input("What grade are you in? "))

if (x == 9):

   print ("Freshman")

elif (x == 10):

   print("Sophomore")

elif (x == 11):

   print ("Junior")

elif (x == 12):

   print("Senior")

else:

   print ("Not in High School")

Explanation:

7 0
2 years ago
Determine the best access modifier for each of the following situations: a. A class Employee records the name, address, salary,
Lorico [155]

Answer:

a. Protected

b. Public

Explanation:

There are four acess modifier in Java.

Default: Acessible only within the same package.

Public: Can be acessed by any class.

Private: Acessible only within the class.

For example, you have a class employee and a private method. This method can only be accessed by an object that is an instance of an employee.

Protected: Used in classes that extend each other. For example, a class of employees would extend employee.

So:

a. A class Employee records the name, address, salary, and phone number.

The best acesses modifier is protected. A class may extended employee but have the same arguments(name, adress, salary, phone number), so it should also have acess to the method.

b. An adding method inside of a class BasicMath.

This method can be used in a variety of packages and projects and classes... and there is no important information regarding security. So the best method is public.

4 0
3 years ago
Energy vampire devices can draw power even when they are turned off or in standby mode?
just olya [345]
Yes that is correct.
3 0
3 years ago
Where do you find the instructions, learning objectives, evaluation and scoring for this aba assignment?.
sp2606 [1]

The instructions, learning objectives, evaluation and scoring for Aba assignment can be found on Preamble of the Applied Behavior Analysis (ABA) assignment.

<h3>What is ABA?</h3>

Applied Behavior Analysis refers to a therapy that is based on the science of learning and behavior.

Hence, the instructions, learning objectives, evaluation and scoring for Aba assignment can be found on Preamble of the Applied Behavior Analysis (ABA) assignment.

Read more about ABA

<em>brainly.com/question/11449763</em>

6 0
2 years ago
If a binary search is applied to an array with 1024 elements, in the worst case, the main loop executes, approximately, _____.
trasher [3.6K]

Answer:

10.

Explanation:

Binary search divides the array to be search each in half according to the value of the element.

The worst case time complexity of binary search is O(logN).

In this case the time complexity will come out to be log₂(1024)=10.

So the binary search can divide this array in half maximum of 10 times.

Hence the main loop will executes 10 times.

7 0
3 years ago
Other questions:
  • AYUDAAA..... DARÉ TODOS LOS PUNTOS QUE PUEDA.
    15·1 answer
  • What error, if any, is in the following code?
    11·1 answer
  • When you're working with a word processing document and you press the DEL Key what happens
    7·2 answers
  • Audiovisual means that a presentation combines film and photos.<br> true or false?
    6·2 answers
  • You implement basic version control and go through the phase of creating a local repository. Initiate the commands to set up tha
    7·1 answer
  • 9. Select the correct answer.
    6·1 answer
  • I need help with this question. its in the photo
    10·1 answer
  • Which statements about editing an existing Contact in Outlook are true? Check all that apply.
    9·2 answers
  • In a _____, there is no skipping or repeating instructions. A. iteration B. sequence C. selection D. conditional
    10·1 answer
  • which responses would you use for a computer or electronic medical record outage? (select all that apply)
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!