- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions

# Program to count number of 5-star reviews required to reach threshold percentage in Python

Suppose we have a list called reviews and a threshold value t. Each item in reviews[i] has [x, y] means product i had x number of 5-star rating and y number of reviews. We have to find the minimum number of additional 5-star reviews we need so that the percentage of 5-star reviews for those items list is at least t percent.

So, if the input is like reviews = [[3, 4],[1, 2],[4, 6]] threshold = 78, then the output will be 7, as in total there were 8 5-star reviews and 12 reviews. To reach 78% 5-star reviews, we need 7 more 5-star reviews.

To solve this, we will follow these steps −

a := 0, b := 0

for each 5-star count c and review count d in reviews, do

a := a + c

b := b + d

if a * 100 >= t * b, then

return 0

delta := t * b - 100 * a

return floor of (delta +(99 - t))/(100 - t)

## Example

Let us see the following implementation to get better understanding

def solve(reviews, t): a = 0 b = 0 for c, d in reviews: a += c b += d if a * 100 >= t * b: return 0 delta = t * b - 100 * a return (delta + (99 - t)) // (100 - t) reviews = [ [3, 4], [1, 2], [4, 6] ] t = 78 print(solve(reviews, t))

## Input

[[3, 4], [1, 2],[4, 6] ],78

## Output

7

- Related Articles
- Program to find number of given operations required to reach Target in Python
- Program to find minimum number of hops required to reach end position in Python
- Program to find minimum number of buses required to reach final target in python
- Program to count number of swaps required to group all 1s together in Python
- Program to count number of minimum swaps required to make it palindrome in Python
- Program to count number of swaps required to change one list to another in Python?
- Program to count number of operations required to all cells into same color in Python
- Program to count number of flipping required to make all x before y in Python
- Program to count minimum number of operations required to make numbers non coprime in Python?
- Program to count number of operations required to convert all values into same in Python?
- Program to count number of walls required to partition top-left and bottom-right cells in Python
- C++ program to count number of operations needed to reach n by paying coins
- Program to find number of combinations of coins to reach target in Python
- Count number of ways to jump to reach end in C++
- Program to Find Minimum Jumps Required to Reach a Value with Different Parity in Python