Maintainability

There are several ways to make sure your program code is understandable.

Use of these techniques will ensure you can return to your code or give it to someone else to use and it will be easily understood.

Example of commented code

#Guess the number game
'''
This is a multiline
comment.
'''
import random #imports the random module to use with number generation (inline comment)
number = random.randint(1, 25) #random.randint generates a random whole number between 1 and 25

# number_of_guesses = 0

for i in range(5):
# while number_of_guesses < 5:
    print('Guess a number between 1 and 25:')
    guess = input()
    guess = int(guess)

    # number_of_guesses = number_of_guesses + 1

    if guess < number:
        print('Your guess is too low')

    if guess > number:
        print('Your guess is too high')

    if guess == number:
        break

if guess == number:
    print('You guessed the number!')

else:
    print('You did not guess the number. The number was ' + str(number))


Some of the lines of code above have been commented out with the # (line 9 for example) to allow the programmer to attempt different solutions and this technique can also help you identify the source of any error.

Using comments within your Python programs helps to make your programs more readable for humans, including your future self. Including appropriate comments that are relevant and useful can make it easier for others to collaborate with you on programming projects and make the value of your code more obvious.