0
0
Pythonprogramming~15 mins

Comments in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Comments in Python
📖 Scenario: You are writing a simple program to calculate the total cost of items you want to buy. To keep your code clear, you will add comments explaining each part.
🎯 Goal: Learn how to write comments in Python to explain your code clearly.
📋 What You'll Learn
Create a variable with a specific value
Add a comment explaining the variable
Write a simple calculation with a comment
Print the result with a comment
💡 Why This Matters
🌍 Real World
Comments are used by programmers to explain their code to others and to themselves when they come back later.
💼 Career
Writing clear comments is important in any programming job to help teams work together and maintain code easily.
Progress0 / 4 steps
1
Create a variable with a comment
Create a variable called price and set it to 100. Add a comment above it that says # Price of the item.
Python
Need a hint?

Use # to start a comment. Write the comment on the line before the variable.

2
Add a comment for a discount variable
Add a variable called discount and set it to 20. Add a comment above it that says # Discount amount.
Python
Need a hint?

Remember to add the comment on the line before the variable.

3
Calculate total with a comment
Create a variable called total that subtracts discount from price. Add a comment above it that says # Calculate total price after discount.
Python
Need a hint?

Use the minus sign - to subtract discount from price.

4
Print the total with a comment
Add a comment that says # Print the total price and then print the variable total.
Python
Need a hint?

Use print(total) to show the result.