- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Find if it is possible to get a ratio from given ranges of costs and quantities in Python

Suppose we have a range of cost from lowCost to upCost and another range of quantity from lowQuant to upQuant, we have to check whether we can find the given ratio r where r=cost/quantity, and lowCost ⇐ cost ⇐ upCost and lowQuant ⇐ quantity ⇐ upQuant.

So, if the input is like lowCost = 2, upCost = 10, lowQuant = 3, upQuant = 9 and r = 3, then the output will be True as the cost = r * quantity = 3 * 3 = 9 where cost is in range [1, 10] and quantity is in [2, 8]

To solve this, we will follow these steps −

for i in range l_quant to u_quant, do

res := i * ratio

if l_cost ⇐ res and res ⇐ u_cost, then

return True

return False

## Example

Let us see the following implementation to get better understanding −

def can_we_find_r(l_cost, u_cost, l_quant, u_quant, ratio) : for i in range(l_quant, u_quant + 1) : res = i * ratio if (l_cost <= res and res <= u_cost) : return True return False l_cost = 2 u_cost = 10 l_quant = 3 u_quant = 9 ratio = 3 print(can_we_find_r(l_cost, u_cost,l_quant,u_quant, ratio))

## Input

2, 10, 3, 9, 3

## Output

True

- Related Questions & Answers
- Find if it is possible to get a ratio from given ranges of costs and quantities in C++
- Check if is possible to get given sum from a given set of elements in Python
- Check if it is possible to create a palindrome string from given N in Python
- Check if it is possible to form string B from A under the given constraint in Python
- Check if it is possible to create a polygon with a given angle in Python
- Find if it is possible to reach the end through given transitions in C++
- Check if it is possible to create a polygon with given n sidess in Python
- Check if it is possible to reach a number by making jumps of two given length in Python
- Check if it is possible to draw a straight line with the given direction cosines in Python
- Check if right triangle possible from given area and hypotenuse in Python
- Check if it is possible to survive on Island in Python
- Check if it is possible to get back to 12 O-clock only by adding or subtracting given seconds in Python
- Check if it is possible to convert one string into another with given constraints in Python
- Check if it is possible to sort the array after rotating it in Python
- Is it possible to get list of defined namespaces in PHP

Advertisements