A textfile stores messages of congratulation for graduates at a secondary school.
A computer program is required to manipulate the textfile. Here is a suggested algorithm written in structured English.
A user is prompted to enter a message.
The message is stored.
The program calls a function checkLength() which accepts the message as a parameter and returns TRUE if the message has 12 or more characters and finishes with an exclamation mark, and FALSE otherwise. This is an example of data validation.
If true is returned, the message is valid and it is appended to a file called congrats.txt. If false is returned, a message Invalid message is displayed.
The user is then prompted to enter another message.
The program stops when the user enters 0 instead of a message and finally the contents of the file are displayed.
Write the program code to implement this structured English algorithm.
Include in your design a function called checklength which has the following pseudocode header:
Don't forget to close the file appropriately.
Write program code for the function SaveStatus.
Have a go at the class register task on File Handling in Python.
Have a go at the mp3 playlist task on File Handling in Python.