Forum¶
We have a file with the statistics concerning a forum, where each line
represents a user and contains the username (str), the number
of posts in the forum, the number of read messages and the number of
sent comments (three int), in this order and separated by a
semicolon (';'). An example of this kind of file is file
data_forum.txt with this
content:
santpere;127;57;8 hackerx;32;2;0 rose;345;764;87 anneta;543;983;12 rllul;2;2;0 apolitic;322;345;32 nini;2372;7533;674 fonaments;372;1372;0
Save all functions into the file named forum.py.
Write the function
no_opinion()that given the name of a file (str) with the format shown, returns alistwith the usernames (str) of those users that have not made any comments. Examples:>>> lusers = ['santpere;127;57;8', 'hackerx;32;2;0', 'rose;345;764;87', ... 'anneta;543;983;12', 'rllul;2;2;0', 'apolitic;322;345;32', ... 'nini;2372;7533;674', 'fonaments;372;1372;0'] >>> with open('data_forum.txt', 'w') as f: ... for e in lusers: ... a = f.write (e+'\n') >>> no_opinion ('data_forum.txt') ['hackerx', 'rllul', 'fonaments']
Note
More tests are provided in file
test-no_opinion.txtThere was a problem during the user registration process. Usernames must have at least 6 characters and we want to know if there are any errors. Write the function
wrong_name()that given the name of a file like the previously shown (str), returnsTrueif there is any username with less than 6 characters andFalseotherwise. Examples:>>> lusers = ['santpere;127;57;8', 'hackerx;32;2;0', 'rose;345;764;87', ... 'anneta;543;983;12', 'rllul;2;2;0', 'apolitic;322;345;32', ... 'nini;2372;7533;674', 'fonaments;372;1372;0'] >>> with open('data_forum.txt', 'w') as f: ... for e in lusers: ... a = f.write (e+'\n') >>> wrong_name ('data_forum.txt') True
Note
More tests are provided in file
test-wrong_name.txtWrite the function
entries()that given the name of a file as described above (str), the name of another file (str) and a number (int), creates this second file and writes in it those users who have made a number of entries to the forum greater than or equal to the given number. In the new created file there is a line for each user with the username and number of entries of that user separated by a space.With the data file
data_forum.txt, shown at the beginning, and executing this statement:... for e in lusers:
A new file with name
visitors.txtwill be created with this content:anneta 543 nini 2372
Note
Tests for automatic debugging are provided in file
test-entries.txt
Solution
A solution of these functions is provided in file forum.py