Choir 2¶
Save all functions into the same file named choir2.py.
A choir has stored the information of its singers in a file. In each
line of this file there are three data, separated by the character
&: the name, the voice (soprano, alto, tenor or bass)b both
str, and a Boolean (bool) showing whether the singer
can act as a soloist (True) or not (False). You can download
file choir2.txt with an example, which is partially shown
here:
Josefina&alto&True Pepet&bass&False Josep&tenor&True Fina&soprano&True
Write the function
gigs()that takes a name of a file as described (str), a voice (str) and an integer,n, (int) and returns a Boolean (bool) which a value ofTrueif there are at leastnsingers with the given voice that can act as soloists andFalseotherwise. Examples:>>> gigs('choir2.txt', 'soprano', 3) True >>> gigs('choir2.txt', 'bass', 2) False
Note
You can download the file with tests
test-gigs.txt.Write the function
dicc_soloists()that takes a name of a file as described (str), and returns a dictionary (dict), where the key is a voice (str) and the value is alistwith those singer’s names (str) with this voice and that can act as soloists. The dictionary must be complete and its lists must be in alphabetical order. Examples:>>> d = dicc_soloists('choir2.txt') >>> if d!= {'bass': ['Xema'], 'soprano': ['Fina', 'Fineta', 'Pepeta'], ... 'tenor': ['Josemari', 'Josep', 'Pep'], ... 'alto': ['Josefina', 'Mariajosep']}: ... print(d)
Note
You can download the file with tests
test-soloists.txt
Solutions
You have some solutions in the file choir2.py