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
GuDViN [60]
3 years ago
8

Write the functiongetInRange (x, a, b)that takes 3 float values and forces to lie between an and is not necessarily less than. I

f x is between the two bounds, it is returned unmodified. Otherwise, if x is less than the lower bound, return the lower bound, or if xis greater than the upper bound, return the upper bound. Use pythons as a programming language

Computers and Technology
1 answer:
OLEGan [10]3 years ago
8 0

Answer:

Here is the getInRange() function:

def getInRange(x,a,b):  

   lower = min(a,b)

   upper = max(a,b)

   if(x<lower):

       x = lower

   elif(x>upper):

       x = upper

   return x

Explanation:

Here is the complete program if you want to take the input float values for x, a and b from user:

x = float(input("Enter x: "))  #prompts user to input float value of x

a = float(input("Enter a: "))  #prompts user to input float value of a

b = float(input("Enter b: "))  #prompts user to input float value of b

def getInRange(x,a,b):  #function definition

   lower = min(a,b)  #computes minimum of a and b and store it to lower

   upper = max(a,b)  #computes maximum of a and b and store it to upper

   if(x<lower):  #if value of x is less than lower bound

       x = lower  # return the lower bound by assigning the value of lower to x

   elif(x>upper):  #if value of x is greater than upper bound

       x = upper  #return the upper bound by assigning value of upper to x

   return x      #function returns the value of x

print(getInRange(x,a,b))  #calls function by passing values for x, a and b and print the result on output screen

   

I will explain this function with an example:

Suppose

x = 1.1

a = 3.3

b = 5.6

Now the method getInRange takes these three values as parameter and works as follows:

lower = min(a,b)  

This statement computes the minimum value of a and b by using min() method and sets the resultant value to lower variable. This becomes:

lower = min(3.3,5.6)

Since 3.3 is less than 5.6 so minimum value is 3.3 Hence

lower = 3.3

upper = max(a,b)

This statement computes the maximum value of a and b by using max() method and sets the resultant value to upper variable. This becomes:

upper= max(3.3,5.6)

Since 5.6 is greater than 3.3 so maximum value is 5.6 Hence

upper = 5.6

if(x<lower):

This statement checks if the value of x is less than value of lower

Since x = 1.1 and lower = 3.3 So, 1.1 is less than 3.3

This means the statement inside this if statement executes:

x = lower

So the value of lower is set to x, So

x = 3.3

Now the elif part will not execute. Program moves to the following statement:

return x

This will return the value of x i.e. 3.3

print(getInRange(x,a,b))    

This statement calls getInRange() method and prints the result on screen. So the output of the above program with input is:

Enter x: 1.1                                                                                                                    Enter a: 3.3                                                                                                                    Enter b: 5.6                                                                                                                  3.3

You might be interested in
Which of the following are safety guidelines when socializing online?
DochEvi [55]

Answer:

All of them execpt five and three.

Explanation:

It is okay to have social media and receive messages.

3 0
2 years ago
Henry wants to use handheld computers to take customers' orders in her restaurant. He is thinking of using custom written, open
DochEvi [55]

Answer: See explanation

Explanation:

Custom written software refers to the software that's developed for some particular organization or users. It's crates in order to meet the unique requirements of a business.

Since Henry is thinking of using custom written, open source software, then a custom written software will be used. Examples of custom written software will be automated invoicing, bug tracking software, E-commerce software solutions etc.

7 0
3 years ago
Which single OSPF network statement will correctly include all the interfaces on a device whose IP addresses only begin with a 1
tester [92]

Answer:

network 10.10.8.0 0.0.3.255 area 0

this will include all the interfaces on a device whose IP addresses only begin with a 10.10.8, 10.10.9, 10.10.10, or 10.10.11.

Explanation:

<em>show ip ospf interface </em>

<em>show ip ospf interface brief</em>

these commands are used to display the interfaces that have been enabled into local ospf . it also shows explanation about them by brief command mentioned above.

<em />

4 0
4 years ago
What is the main difference between a LAN and a WAN?
snow_tiger [21]
LAN is local area network and WAN is wide are networks, so it’s the distance they span
8 0
3 years ago
What method parses its string argument to determine whether the string can be converted to a number?
den301095 [7]
The correct answer is: Tryparse method
6 0
3 years ago
Other questions:
  • Human centered technology often recommends a0 to computer designers and manufacturers, telling them how to make systems and the
    12·2 answers
  • Ranges of IP address that anyone can use for their internal networks are known as ______.
    8·2 answers
  • Because health and safety are important in all workplaces, not just hazardous ones, what working conditions must ALL employers p
    10·2 answers
  • IF ACCURATE = BRAINLY (if u answer rubbish randomness= reported AND if you got questions dont ask in answer slot= reported)
    13·1 answer
  • All systems have ___________.
    9·2 answers
  • Consider Statement 1: All prime numbers greater than 3 are equal to a multiple of six, plus 1 or minus 1. Let P(x) be the statem
    7·1 answer
  • Which option is the easiest way to configure macros in Access 2016?
    6·1 answer
  • Guys, if I'm going back to 505 and it's a 7-hour flight or a 45-minute drive how do I get to 505?
    12·1 answer
  • Display the Approval Form worksheet and create an IF statement in cell B13 to determine if the applicant is eligible for a perso
    7·1 answer
  • True or false: you should reuse passwords on multiple websites because it will help you remember those passwords
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!