Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Task one: (1 mark) Design a function to check whether a document with the format CPF, the input for the function is a file path.
Task one: (1 mark) Design a function to check whether a document with the format CPF, the input for the function is a file path. The output is a Boolean variable. If the file has the specified format, return True. Else, return False. Specifically, there are three criterions your function should check, 1) if the text has title, author, and body 2) if each part is separated by two blank lines 3) each paragraph in the file body is separated by one blank line. If any one of the criterions is violated, your function should return False. Any blank part is regarded as violating the first rule, e.g., an empty body means that the file body part is missing. Write the code for this function in a file named task1.py. The format CPF: CPF is a custom document format. Each document contains three parts: Title, Author, and Body. Each part is separated by two blank lines. In the document Body, each paragraph is separated by one blank line. Document example is attached. Example: How to learn python? Nick Referencing the official tutorial is a good way to learn. You don't need to memorize the usage of all APIs, just remember the most commonly used APIs. Try writing some programs yourself. With practice, you'll develop your own programming style, know how to solve common problems, and how to seek professional help. Another good way to learn is to read other people's code (such as the code on github) and learn how others solve problems. Task one: (1 mark) Design a function to check whether a document with the format CPF, the input for the function is a file path. The output is a Boolean variable. If the file has the specified format, return True. Else, return False. Specifically, there are three criterions your function should check, 1) if the text has title, author, and body 2) if each part is separated by two blank lines 3) each paragraph in the file body is separated by one blank line. If any one of the criterions is violated, your function should return False. Any blank part is regarded as violating the first rule, e.g., an empty body means that the file body part is missing. Write the code for this function in a file named task1.py. The format CPF: CPF is a custom document format. Each document contains three parts: Title, Author, and Body. Each part is separated by two blank lines. In the document Body, each paragraph is separated by one blank line. Document example is attached. Example: How to learn python? Nick Referencing the official tutorial is a good way to learn. You don't need to memorize the usage of all APIs, just remember the most commonly used APIs. Try writing some programs yourself. With practice, you'll develop your own programming style, know how to solve common problems, and how to seek professional help. Another good way to learn is to read other people's code (such as the code on github) and learn how others solve problems
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started