0% found this document useful (0 votes)
61 views

Part 3: Adding Comments To Your Code

This document introduces how to add comments to Python code in 3 levels: rookie, pro, and beast. At the rookie level, readers learn to add single-line comments with # and comment out code temporarily. At the pro level, readers write comments explaining programming techniques. Finally, at the beast level, readers write precise comments allowing others to understand their code. Challenges require applying these skills through code samples and a debugging question. A review identifies areas of confidence and improvement.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Part 3: Adding Comments To Your Code

This document introduces how to add comments to Python code in 3 levels: rookie, pro, and beast. At the rookie level, readers learn to add single-line comments with # and comment out code temporarily. At the pro level, readers write comments explaining programming techniques. Finally, at the beast level, readers write precise comments allowing others to understand their code. Challenges require applying these skills through code samples and a debugging question. A review identifies areas of confidence and improvement.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Introduction to Python

Programming
Part 3: Adding
Comments to
your Code
How to use this resource
Skill Explanations: Pink Slides
• Within each unit, you will learn how to develop
and apply a range of Python programming skills.
Skill explanations are in pink.
Tasks: Rookie Pro Beast
• After reading the explanation of a skill, apply it
within the given tasks. The tasks are categorised
into Rookie (Easy), Pro (Medium) or Beast (Hard).
Challenges: Rookie Pro Beast
• Once you have learned how to apply your new
skills, demonstrate your ability by completing the
given challenges. Don’t forget the debugging task!
• Once complete, review your performance!
Learning Objectives
Rookie
• To understand why adding comments to your code is useful.
• To be able to add comments within your python code.
Pro
• To write comments which help to explain what programming
techniques you have used.
Beast
• To write clear and precise comments which means that someone
else can understand your programming techniques.
Skill Contents
Once you complete a skill, colour code
Contents Confidence
the box to show your level of Level
confidence. You can always revisit the Adding comments in Python #
skill later on to boost your confidence.
Comment out code
Key Colour
Code
I am very good at this skill
and could show a friend
how to do it.
I am confident I can
perform this skill on my
own.

I need to improve my
understanding of this skill.
Why do we add comments?
Programmers add comments within their code for the following reasons:
• It helps explain the programming techniques written and how they work.
• If a programmer wants to reuse their code in the future, using comments
will help identify the required piece of code.
• They provide explanations for other people who may wish to use the
code, or learn the same programming technique.
Skill 1: Adding comments in python
• To add a comment, simply type in a hashtag symbol # followed by the
required information.
• You write it like this:

• As a rule, always add comments to explain the code below the


comment.
Task 1: Rookie
1. Store the phrase Hello World within a suitable variable.
2. Print the variable.
3. Add comments to your code to explain what you have done.
Flowchart Pseudo code Python
Add comments to the
code below:
START
variable = Hello world
OUTPUT: variable
EEND
Task 1: Solution
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Skill 2: Comment out code
• Another useful technique you could use comment for is to temporarily
remove a line of code.
• For example, if you only want to use a print command to check if a
variable is storing the correct information, you may want to comment it
out:

As you can see,


this piece of code
is only used to
check that data is
being stored in
the name
variable. It can be
uncommented at
a later date.
Task 2: Pro
1. Write out the code below:
2. Comment out the code lines that print out variables b and c so only x is
outputted.

Python
Skill Task 2: Solution
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Programming Challenges
• Now you have learned some programming skills, it’s time to
put them into practice!
• Complete the following programming challenges. Start with
the Rookie challenge and see how far you can push yourself.
• Finally, complete the debugging challenge.
• Once you have finished your challenges, complete the
review. Look back at the skills you have learned so far to help
you solve the challenge.
Add a print screen of
Programming Challenge: Rookie your solutions to the
next slide.

Write out the code below and add a suitable comment to explain
what is happening for each line of code:

1 Mark
Programming Challenge: Rookie - Answer
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Add a print screen of
your solutions to the
Programming Challenge: Pro next slide.

Write out the code below and add a suitable comment to explain what
is happening for each line of code:

1 Mark
Programming Challenge: Pro - Answer
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Add a print screen of
your solutions to the
Programming Challenge: Beast next slide.

Write out the code below and add a suitable comment to explain what
is happening for each line of code:

1 Mark
Programming Challenge: Beast - Answer
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Debugging Question
Which of the following lines of code below would output the following statement:

Highlight the correct cell in green:

1 Mark
Complete the table below to help you identify what
Challenges Review areas you are confident at and which areas you need
to improve further:
Challenge Your Score (Max 1 mark each)
Rookie Challenge
Pro Challenge
Beast Challenge
Debugging Challenge

Unit Review
What Went Well:

Even Better If:

You might also like