MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / ratio

Method ratio

greedy_methods/fractional_cover_problem.py:13–30  ·  view source on GitHub ↗

Return the value-to-weight ratio for the item. Returns: float: The value-to-weight ratio for the item. Examples: >>> Item(10, 65).ratio 6.5 >>> Item(20, 100).ratio 5.0 >>> Item(30, 120).ratio 4.0

(self)

Source from the content-addressed store, hash-verified

11
12 @property
13 def ratio(self) -> float:
14 """
15 Return the value-to-weight ratio for the item.
16
17 Returns:
18 float: The value-to-weight ratio for the item.
19
20 Examples:
21 >>> Item(10, 65).ratio
22 6.5
23
24 >>> Item(20, 100).ratio
25 5.0
26
27 >>> Item(30, 120).ratio
28 4.0
29 """
30 return self.value / self.weight
31
32
33def fractional_cover(items: list[Item], capacity: int) -> float:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected