Professional Documents
Culture Documents
Ex 1
Ex 1
In a marketplace, there are multiple places that sell pineapple at different size and cost.
Implement a program to find the place that sells quality pineapple with largest size and
minimum cost by getting the size and cost in array.
Algorithm:
2. Input Validation:
3. Initialize Variables:
• For each place, compare its size and cost with the current maximum size and
minimum cost.
• If the size is greater than the current maximum size or if the size is the
same but the cost is lower, update the variables
(best_pineapple_index, max_size, min_cost).
5. Output Result:
if len(sizes) != len(costs):
print("Error: Sizes and costs arrays must have the same length.")
return None
return None
best_pineapple_index = 0
max_size = sizes[0]
min_cost = costs[0]
best_pineapple_index = i
max_size = sizes[i]
min_cost = costs[i]
return best_pineapple_index
# Example usage:
sizes = [5, 8, 7, 6]
best_size = sizes[best_pineapple_index]
best_cost = costs[best_pineapple_index]
print(f"The place that sells the quality pineapple with the largest size ({best_size}) and
minimum cost ({best_cost}) is at index {best_pineapple_index}.")
Output:
The place that sells the quality pineapple with the largest size (8) and minimum cost (3.0) is
at index 1.