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
agasfer [191]
3 years ago
8

Code scramble: make the program sort the three numbers x, y and z into increasing order, so that x has the smallest value, y has

the next smallest value, and z has the largest value. Drag and drop with your mouse to rearrange the lines.
Engineering
1 answer:
riadik2000 [5.3K]3 years ago
3 0

Answer:

This question is taken from code scramble exercise which has scattered lines which are to be arranged by dragging and dropping with mouse to  to get the desired output in which x has the smallest value, y has the next smallest value, and z has the largest value. So the correct arrangement is as following:

tmp=max(x,y)  

x=min(x,y)  

y=tmp  

tmp=max(y,z)  

y=min(y,z)

z=tmp  

tmp=max(x,y)  

x=min(x,y)  

y=tmp

Explanation:

So the flow works as following:

First the maximum of x and y is taken and the result is stored in a temporary variable tmp which is used so that the original values do not get affected or modified by the operations performed by the functions. Lets say that x=30 y=15 and z=40

Now the max() functions returns the maximum from the values of x and y. As x=30 and y=15 so value of x is stored in tmp which is 30 as 30>15

Next the min() function finds the minimum from the values of x and y and stores the result in x. As the minimum value is 15 so this value is stored in x and now x=15

y = tmp means now the value in tmp is copied to y, So y = 30

Next the max() function finds the maximum value from the values of y and z. As y=30 and z=40 So the maximum value is 40 so tmp variable now contains the value 40.

Next the min() function finds the minimum from the values of y and z and stores the result in y. As the minimum value is 30 so this value is stored in y which means y remains 30 so, y=30

z = tmp means now the value in tmp is copied to z, So z= 40

Now the max() functions returns the maximum from the values of x and y. After the operations of above functions the new value of x and y are: x=15 and y=30 so value of y is stored in tmp which is 30 as 30>15

Next the min() function finds the minimum from the values of x and y and stores the result in x. As the minimum value is 15 so this value is stored in x and x remains: x=15

y = tmp means now the value in tmp is copied to y, So y remains: y = 30

So the final values of x, y and z are:

x = 15 y = 30 z = 40

If you want to make a program which sort the values in x, y and z then i am providing a simple Python program that serves the purpose:

x = int(input("enter first number: "))

y = int(input("enter second number: "))

z = int(input("enter third number: "))

a1 = min(x, y, z)

a3 = max(x, y, z)

a2 = (x + y + z) - a1 - a3

print("x =",a1,"y=",a2,"z=",a3)

The program asks user to enter the value for x, y and z.

Then the minimum value from the values of x,y and z is computed using min() function and the result is stored in a1. This will be the value of x. Then the maximum value from value of x,y and z is computed using max() function and the result is stored in a2. This will be the value of z. Next the statement: a2 = (x + y + z) - a1 - a3  works as following:

Lets say the values of x = 30 y = 15 and z = 40 So a1 = 15 and a2 = 40

a2 = 30 + 15 + 40 - 15 - 40

a2 = 30

This is the value of y

So  print("x = ",a1,"y = ",a2,"z = ",a3) displays the following output:

x = 15 y = 30 z = 40

You might be interested in
What is the name of the part that supports the headlight assembly?
Shkiper50 [21]
A headlight assembly is made up of many parts that work together smoothly. One of these components is the headlight bracket. Sometimes known as “headlight mounting bracket,” it keeps the headlamp affixed to the header. The headlight bracket is made from sturdy material like plastic or steel.
8 0
3 years ago
Which of the following activities can help expand engineers' creative thinking capabilities?
Assoli18 [71]

Answer:

team building exercises

Explanation:

3 0
2 years ago
Read 2 more answers
10. True or False: You should select your mechanic before you experience vehicle failure.
ra1l [238]

Answer:

True

Explanation:

Always see a professional if you have any issues that is not in your scope of practice

7 0
3 years ago
Read 2 more answers
When we utilize a visualization on paper/screen, that visualization is limited to exploring: Group of answer choices Relationshi
Mila [183]

Answer:

As many variables as we can coherently communicate in 2 dimensions

Explanation:

Visualization is a descriptive analytical technique that enables people to see trends and dependencies of data with the aid of graphical information tools. Some of the examples of visualization techniques are pie charts, graphs, bar charts, maps, scatter plots, correlation matrices etc.

When we utilize a visualization on paper/screen, that visualization is limited to exploring as many variables as we can coherently communicate in 2-dimensions (2D).

6 0
3 years ago
Write the following decorators and apply them to a single function (applying multiple decorators to a single function): 1. The f
natita [175]

Answer:

Complete question is:

write the following decorators and apply them to a single function (applying multiple decorators to a single function):

1. The first decorator is called strong and has an inner function called wrapper. The purpose of this decorator is to add the html tags of <strong> and </strong> to the argument of the decorator. The return value of the wrapper should look like: return “<strong>” + func() + “</strong>”

2. The decorator will return the wrapper per usual.

3. The second decorator is called emphasis and has an inner function called wrapper. The purpose of this decorator is to add the html tags of <em> and </em> to the argument of the decorator similar to step 1. The return value of the wrapper should look like: return “<em>” + func() + “</em>.

4. Use the greetings() function in problem 1 as the decorated function that simply prints “Hello”.

5. Apply both decorators (by @ operator to greetings()).

6. Invoke the greetings() function and capture the result.

Code :

def strong_decorator(func):

def func_wrapper(name):

return "<strong>{0}</strong>".format(func(name))

return func_wrapper

def em_decorator(func):

def func_wrapper(name):

return "<em>{0}</em>".format(func(name))

return func_wrapper

@strong_decorator

@em_decorator

def Greetings(name):

return "{0}".format(name)

print(Greetings("Hello"))

Explanation:

5 0
3 years ago
Other questions:
  • What is the major drawback in nanocrystalline alloys? a)- high brittleness b)-low hardness c)-rapid grain growth upon heating d)
    9·1 answer
  • Why is it a good idea to lock your doors while driving?<br> WRITER
    10·1 answer
  • Draw the hierarchy chart and then plan the logic for a program needed by Hometown Bank. The program determines a monthly checkin
    8·1 answer
  • "The office personnel at Garden Glory use a database application to record services and related data changes in this database. F
    9·1 answer
  • The amount of time an activity can be delayed and yet not delay the project is termed:_________
    14·1 answer
  • What is the maximum volume flow rate, in m^3/hr, of water at 15.6°C a 10-cm diameter pipe can carry such that the flow will be l
    9·1 answer
  • Where you live might affect how often you change your cabin air filter.<br> True<br> False
    8·1 answer
  • which systems engineering support discipline has the goal to ensure that support considerations are an integral part of the syst
    14·1 answer
  • The two major forces opposing the motion of a vehicle moving on a level road are the rolling resistance of the tires, Fr, and th
    7·1 answer
  • Five Safety for vernier height guage​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!