Company vote 1¶
The file votes.txt contains the result
of the vote held in a company. In each line there is the name of a
shareholder (str), the number of shares she has
(int), a Boolean (bool) that is True if she is a
partner founder of the company and False otherwise, and another
Boolean (bool) that is True if she approves the reform
proposed and False otherwise. The file contains the following
lines:
Dani 100 True True Manel 5 False True Maria 30 True True Joan 20 True True Nuria 150 False False
The first two lines correspond to the partner founder Dani, who has 100 shares and to the partner (not-founder) Manel, with 5 shares. Both have approved the reform. The rules to approve a reform in this company are the following:
The partner founders have the right to veto. That is, if a partner founder votes against the reform, this is rejected.
The vote of each shareholder is weighted with the number of shares she has. For instance, the vote of a shareholder has a value of 200 if she has 200 shares.
Write function company() that takes the name of a file
(str) of the aforementioned characteristics, and returns a
Boolean (bool) showing whether the reform has been approved
or not. The reform will be approved if nobody with a right to veto has
voted against it, and if more than half of the (weighted) votes are
favourable. If the reform has been approved this function also returns
the approval percentage (float); if it has not been approved
due to a veto it must also return the string 'veto', and if it has
not been approved due to the percentage, it must also return it
(float).
In the example given, the reform would pass since no partner founder
has voted against and there are 155 votes in favour and 150
against. Therefore the function will return True and a percentage
of 50.82.
Save this function into file company.py
Note
More tests are provided in file test-company.txt
Solution
A solution of these functions is provided in file
company.py.