Coding Standard For Python Coding Assignments Sample

How Do I Use Python For Automation?

Coding Standard For Python Coding Assignments Sample

Programming Assignment Help

At Programming Homework Tutors, we believe in providing our students with practical, real-world examples of how to apply the concepts they learn in class. That’s why we’ve developed a variety of sample projects to help you see how our courses can be used to create impactful solutions in your field of study.

When you convert a design document (algorithm) into Python source code, one of your primary goals should be to write the source code and internal documentation in such a way so that it is easy to verify that the source code conforms to the design, and so that it is easy to debug, test, and maintain the source code.  The coding standard below is designed to assist you in achieving this goal.

  

1.     Source Code Format

Source code lines will be no more than 80 characters long. Break long lines into multiple shorter lines using the continuation character (“\”).

Only one statement will be included on a given line of the source code.

Use 4 spaces for indentation.

Blank lines and spaces will be used to enhance the readability of both source statements and comments.

All import statements will appear after the source code header and before any other Python code in the program.

All function definitions will appear after the import statements and before any other Python code in the program.

 

2.     Source Code Header

Each source code file (including class files) will contain an introductory block of comments that identifies the assignment and gives a brief overview of the program.  Note: Must fill-in the information in-between [ and]. For example:

 

    ###########################################################

    #  Assignment #:  [ ]

    # Author Name: [ ]          VCCS Email:  [ ]

    # Assignment Description: [ ]

    # 

    #  Problem Algorithm: 

    Note: below is a sample algorithm. It must be replaced by the algorithm for the given problem in the assignment text.

    #    prompt for an integer

    #    input an integer

    #    loop while not end-of-data

    #       call function to count number of digits in integer

    #       output the number of digits

    #       prompt for an integer

    #       input an integer

    #    display closing message

    ###########################################################

 

3.     Descriptive Comments

The source code will include comments that describe the functionality of significant blocks of code. Comments are particularly important before all blocks of code that perform major data manipulations or error processing.

For readability, each comment will be indented at the same level as the block of code that it describes or, if it fits within the 80-character limit and describes just a single line of code, to the right of that line.

 

Place comments to indicate:

The purpose of objects that are not clear from their names.

Where something is “tricky”, “clever”, or “unusual”; if it required thought on your part, it should be commented.

 

Note:

If it was hard to write, it is probably hard to read. Add a comment.

 

4.     Mnemonic Identifiers

Meaningful identifiers taken from the problem domain will be used for all names.  Furthermore, a name will be used for only one purpose (the same name will not be used for more than one purpose). Identifiers may be composed of multiple words. The assignment/program name must say/reflect what the assignment/program is doing/accomplishing. It should not contain your name, course name, assignment number…etc. 

 

5.     Symbolic Constants

Symbolic constants will be used instead of embedding arbitrary numeric and character constants in the source code.  Use “upper with under” style for all symbolic constants:

 

    HEAT_OF_FUSION = 79.71    # Calories to melt one gram of ice

 

6.     Variable and Function Names

Use “lower with under” style for all variable and function names.  In some situations, it is appropriate to append type information to variable names as a visual reminder about the purpose of those variables:

 

    student_count = 0         # Number of students in class     fahrenheit_float = 0.0    # Temperature in Fahrenheit

 

7.     Function Header and Class Method Header

Using docstrings (delimited by triple double-quotes), each function will contain an introductory block of comments that: a. explains the purpose of the function and 

describes all information passed to the function, modified by the function, and

returned by the function (parameters and global data objects).

It will also describe any assumptions about the information passed to the function that is needed for the function to work correctly.

Do the same for each class methods. For example:

 

    def count_digits( value ):

        “””

        Function Description: Count the number of digits in an 

integer value.

        value:  The value to be processed (int)

        Returns:  The number of digits in value (int)

        “””

     

    def add_assignment( grade_book, possible_pts ):

        “””

        Function Description: Adds a new assignment to a grade book.         grade_book: the grade book (dict)          maps assignment names (str) to grad dicts,          where a grade dict maps student PIDS (str)          to grades (float)         grade_book is both read and modified         possible_pts: the total points possible,         must be positive  

        “””        

8.     Class Names

Use “CamelCase” style for all class names: “CamelCase” means the first character of each word must be capitalized. See examples: 

    class SalariedEmployee

    class HourlyEmployee

 

Disclaimer

The sample projects provided on our website are intended to be used as a guide and reference for educational purposes only. While we have made every effort to ensure that the projects are accurate and up-to-date, we do not guarantee their accuracy or completeness. The projects should be used at your own discretion, and we are not responsible for any loss or damage that may result from their use.
At Programming Homework Tutors, we are dedicated to helping students and educators achieve their goals by providing them with the resources they need to succeed. Our website offers a variety of tools and resources that can help you with the project mentioned above.
Whether you need help with research, project management, or technical support, our team of experts is here to assist you every step of the way. We offer online courses, tutorials, and community forums where you can connect with other learners and get the support you need to succeed.
If you’re looking to take your skills to the next level and make an impact in your field, we invite you to explore our website and see how we can help you achieve your goals.

No Comments

Post A Comment

This will close in 20 seconds