Showing posts with label Complete study notes for Python programming. Learn how to add comments. Show all posts
Showing posts with label Complete study notes for Python programming. Learn how to add comments. Show all posts

Wednesday, September 23, 2026

Python Comments, Variables, Input & Data Types | ICT Notes Cambridge-Lower-Secondary-Computing-7-Ben-Barnes-Tristan-Kirkpatrick Edexcel Tuition Class Sri Lanka

🐍 Python: Comments, Variables, Input & Data Types

Complete Guide with Practice Exercises & Solutions

📚 About this guide: Complete, exam-friendly notes for Python Programming Basics. Learn how to add comments, use variables, capture user input with input(), understand data types (string, integer, float), and practice with real exercises and solutions.
Concept 1

What Are Comments?

Adding comments to code allows you to explain what the code does or to provide extra information about the code. In Python, you start a comment with a hash (#) symbol. Any text on a line after a # symbol will be ignored by the interpreter.

Example

Comments in Action

# This is an Adventure Game about The Digital Sweet Shop
# The program was written by me
#
#
#
# The next few lines give the introduction

print("Welcome to The Digital Sweet Shop")
print()
print("You have been invited to take part in a competition in the shop.")
print("You must find the chocolate room where you will be asked a question.")
print("If you get it right you will receive letters which are part of a password and a clue.")
          
🎯 Exam Tip: Comments improve code readability and help other programmers (or yourself later) understand what the code does. They are essential for good programming practice!
Concept 2

What is a Variable?

A variable is a named location in the computer's memory that stores data of a particular type. Data can either be assigned to a variable in the program itself, or it can be assigned from input from the user.

name = "Ardeel"
age = 12
address = "Station Road"
colour = "Red"
          
Concept 3

Printing Variables

To print the contents of a variable, use the print() statement. To combine text and a variable, use a comma (not inside quotation marks).

# Print just the variable
print(name)
# Output: Ardeel

# Combine text and variable
print("Your name is", name)
# Output: Your name is Ardeel
          
🔑 Keyword:
  • Variable: A named memory location used to store data of a given type during program execution; a variable can change value as the program runs.
Concept 4

The input() Function

The input() command allows users to enter information into the program and store it in a variable.

name = input("What is your name? ")
print("Hello", name)
          
CommandDescription
input()Used to take input from a user. If you wish to store this input, you need to assign it to a variable.
Scratch vs Python

Comparison: Scratch Blocks → Python Code

Scratch BlocksPython Code
when 🟢 clicked
ask What's your name? and wait
set [name ▾] to (answer)
say (join [Hello ] (name))
name = input("What's your name? ")
print("Hello", name)
Practice

Practice Task: Name and Number

Create a program that:

  • Asks the user to 'Enter your name' and stores it in a variable called name
  • Asks the user to 'Enter a number between 1 and 10' and stores it in a variable called number
  • Uses print to create output like this:
Enter your name Khalil
Enter a number between 1 and 10 6
Your name is Khalil and the number you entered was 6
          
💡 Solution:
name = input("Enter your name ")
number = input("Enter a number between 1 and 10 ")
print("Your name is", name, "and the number you entered was", number)
            
Concept 5

What Are Data Types?

Variables can hold different data types. To store data, you must decide on a name and a data type for the variable first.

Data TypeExampleDescription
String'Hello World', 'WE5694MC'Any textual characters (letters, numbers, symbols)
Integer24, -10Any whole number (no decimal point)
Real (Float)6.98, -0.045Any number with a decimal point
⚠️ Important: In Python, the data type real is referred to as float. This is short for 'floating point number', which is a decimal number.
Concept 6

Variable Examples

Variable NameData TypeReason
playerageIntegerStores a whole number (age in years)
playernameStringStores letters/text characters

The variable names have been chosen as playerage and playername, but they could have been called anything we wanted.

Concept 7

Input Function & Data Types

To capture data from the user, you use the input() function. The input function captures user input as a string data type. This contains numbers, letters, and symbols.

playername = input("What is your name? ")
print("Welcome", playername)
          

Examples of string data type: 'Robot', '@password123', '**WWW777'

Keywords

Essential Vocabulary

  • Data type: The different ways in which data can be stored, e.g., integer, string, decimal number
  • Integer: Whole number
  • Real: Any number with a decimal point, such as 1.2 or 56.8
  • Float: Another name for the data type real; short for 'floating point number'
  • Input function: A function that Python uses to capture string data from users
  • String: Data that is made up of letters, numbers, or any characters on the keyboard
💡 DID YOU KNOW? Variables are not used just in computer programming; they are used in other applications as well. Spreadsheets make use of variables too, but they are referred to as cell references. Variables are extremely powerful as you can use them to store data and model different scenarios (weather forecasting, financial markets, aerodynamics).
Exercise 1

Rewrite Scratch Programs in Python

Program 1 (Scratch): Ask for a word and display it back

✅ Python Solution:
word = input("Enter a word: ")
print("The word you entered was", word)
            

Program 2 (Scratch): Ask for age and location

✅ Python Solution:
age = input("How old are you? ")
print("You are", age, "years old")

live = input("Where do you live? ")
print("You live in", live)
            
Exercise 2

Identify Data Types

Look at the Python code below and identify the data type for each variable:

name = "Maryam"
cardNumber = "0012563943029845"
balance = 145.98
address = "Mall Road"
age = 11
          
Variable DescriptionVariable NameData TypeExplanation
Name on bank cardnameStringContains text characters representing a name
Bank card numbercardNumberStringStored as text because it contains leading zeros and is not used for calculations
Bank account balancebalanceFloat (Real)Contains a decimal point representing monetary value
AddressaddressStringContains a mix of letters and numbers representing text
AgeageIntegerContains a whole number representing years
Exercise 3

Complete the DataTypes.py Program

Edit the code so when it runs, it looks like this:

Name: Maryam
Age: 13
Address: Station Road
Bank Card Number: 0012563943029845
Current Balance: 145.98
          
✅ Python Solution:
# Updated variables to match final output requirements
name = "Maryam"
cardNumber = "0012563943029845"
balance = 145.98
address = "Station Road"
age = 13

# Output formatting statements
print("Name:", name)
print("Age:", age)
print("Address:", address)
print("Bank Card Number:", cardNumber)
print("Current Balance:", balance)
            

❓ Frequently Asked Questions (FAQ)

Q: How do you add comments in Python? A: In Python, you add comments by starting a line with a hash (#) symbol. The Python interpreter ignores any text on a line after the # symbol, making it useful for explaining code or providing extra information.
Q: What is a variable in Python? A: A variable is a named location in the computer's memory that stores data of a particular type. Data can be assigned to a variable in the program itself or from user input, and it can change value as the program runs.
Q: What does the input() function do in Python? A: The input() function allows users to enter information into the program. It captures user input as a string data type and stores it in a variable. For example: name = input('What is your name? ')
Q: What are the three main data types in Python? A: The three main data types are: 1) String - textual characters like 'Hello World', 2) Integer - whole numbers like 24 or -10, 3) Real/Float - numbers with decimal points like 6.98 or -0.045.
Q: Why is a bank card number stored as a string instead of an integer? A: A bank card number is stored as a string because it contains leading zeros and is not used for mathematical calculations. Storing it as an integer would remove the leading zeros.
🎓 SRI LANKA ONLINE ICT TRAINING

Expert ICT, Computer Science, Coding & Digital Marketing Classes

Learn ICT, Computer Science, Programming, Web Development and Digital Marketing with practical, career-focused guidance.

💬 Join WhatsApp ▶ Watch Tutorials

🚀 Learn Today. Build Tomorrow.

Welcome to our Sri Lanka Online ICT & Computer Classes community! We provide Online Tuition Classes, Home Visit Classes and Individual / Group Classes for students and professionals. Whether you are a school student, university student, beginner programmer or entrepreneur, we help you develop practical IT skills for education and career growth.

💡 Explore Our Training & Services

🎓 University Project Guidance

Technical guidance for university assignments and final-year IT projects.

  • BIT / BSc / IT / ICT Projects
  • Final Year Project Guidance
  • PHP & MySQL Projects
  • Python & Java Projects
  • Database & Web Applications
  • Project Ideas & Documentation

🤖 AI, Coding & Software

Develop programming knowledge and practical software development skills.

  • Python Programming
  • C & Java Programming
  • PHP & JavaScript
  • HTML & CSS
  • jQuery & AJAX
  • AI & Smart Applications

🏫 School ICT Classes

Interactive ICT and Computer Science lessons for school students.

  • Grade 1 – Grade 11
  • G.C.E. O/L ICT
  • G.C.E. A/L ICT
  • GIT Classes
  • School ICT & Internal Tests
  • Past Papers & Revision

🌐 Web Design & Development

Build websites and database-driven applications for individuals and businesses.

  • Website Design
  • Website Development
  • WordPress Development
  • PHP & MySQL
  • HTML / CSS / JavaScript
  • Website SEO & Maintenance

📢 Digital Marketing

Grow your brand online with social media and digital marketing support.

  • Digital Marketing
  • Facebook Page Management
  • Instagram Marketing
  • TikTok & YouTube
  • Content Creation & SEO
  • Facebook Ads & Reels

💻 Computer & IT Skills

Build essential computer skills from absolute beginner to advanced level.

  • Computer Fundamentals
  • MS Word, Excel & PowerPoint
  • Excel Formulas & Macros
  • Oracle / MySQL / MS SQL
  • AWS, Linux & DevOps
  • Freelancing & IT Skills

📚 Learn With Your Curriculum

Support for Sri Lankan Local Curriculum, Cambridge and Pearson Edexcel programs.

🇱🇰 Sri Lankan Local Curriculum

  • Grade 01 – Grade 11 ICT
  • G.C.E. O/L ICT
  • G.C.E. A/L ICT
  • GIT Classes
  • Term Test Preparation
  • Model Papers & Notes
  • English / Sinhala / Tamil Medium

📘 Pearson Edexcel

  • iPrimary Computing
  • iLowerSecondary Computing
  • International GCSE ICT
  • International GCSE Computer Science
  • GCSE Computer Science
  • International A Level IT
  • International A Level Computer Science

📗 Cambridge Curriculum

  • Cambridge Primary Computing
  • Cambridge Lower Secondary Computing
  • Cambridge IGCSE ICT
  • Cambridge IGCSE Computer Science
  • Cambridge O Level Computer Science
  • AS & A Level IT
  • AS & A Level Computer Science

💻 Programming & Software Development

🛠️ Programming Languages & Technologies

✅ Python Programming ✅ C Programming ✅ Java Programming
✅ PHP Programming ✅ JavaScript ✅ HTML & CSS
✅ jQuery & AJAX ✅ ASP.NET ✅ VB.NET
✅ VB6 ✅ MySQL ✅ MS SQL Server
✅ MS Access ✅ Oracle Database ✅ Database Design
✅ SQL Queries ✅ Database Programming ✅ Software Development

🌐 Web Design & Development

  • ✅ Website Design
  • ✅ Website Development
  • ✅ WordPress Website Development
  • ✅ HTML / CSS / JavaScript
  • ✅ PHP & MySQL
  • ✅ WordPress SEO
  • ✅ Website Maintenance
  • ✅ Web Applications
  • ✅ Database-Driven Websites

🎓 University & Final Year IT Projects

🧑‍💻 Project Development

  • BIT / BSc / IT / ICT Projects
  • PHP & MySQL Projects
  • Python Projects
  • Java Projects
  • Web Application Projects
  • Database Projects

📄 Documentation & Practical

  • Project Ideas
  • System Architecture
  • Database Design
  • Assignments Guidance
  • Practical Implementation
  • Technical Documentation

🧠 AI & Smart Applications

  • AI Application Concepts
  • Machine Learning Modules
  • Automation Applications
  • Step-by-Step Coding
  • System Implementation
  • Project Learning Support

📊 Database, Cloud & IT Training

✅ Oracle Database ✅ MySQL ✅ Microsoft SQL Server
✅ Microsoft Access ✅ Database Design ✅ SQL Queries
✅ AWS Cloud ✅ Linux ✅ UNIX
✅ Windows Server ✅ DevOps ✅ SRE
✅ Automation ✅ Software Testing ✅ Freelancing Skills

📱 Digital Marketing & Social Media

✅ Digital Marketing ✅ Facebook Page Setup & Management
✅ Instagram Marketing ✅ TikTok Marketing
✅ YouTube Channel Setup ✅ Social Media Management
✅ Content Creation ✅ SEO
✅ Facebook Ads ✅ Instagram Reels
✅ LinkedIn Branding ✅ Social Media Campaign Planning
✅ Hashtag Strategy ✅ Insights & Engagement

🖥️ Microsoft Office & Digital Skills

  • ✅ MS Word
  • ✅ MS Excel
  • ✅ MS PowerPoint
  • ✅ Excel Formulas
  • ✅ Excel Automation & Macros
  • ✅ Computer Fundamentals
  • ✅ Digital Literacy
  • ✅ Multimedia Presentations

⭐ Why Join Our Classes?

🌍
Online & Home Visit Classes
👥
Individual & Group Classes
🗣️
English / Sinhala / Tamil
📚
School & University Support
📝
Past Papers & Model Papers
💻
Practical Programming
🚀
Beginner to Advanced Skills
🎯
Career-Focused Learning

📞 Ready to Start Learning?

Book your online class or contact us for ICT training, programming courses, university project guidance and digital marketing services.

📱 Call / WhatsApp: +94 729622034

📧 Email: itclasssl@gmail.com

💻 Skype: ITClassSL

💬 Contact Us on WhatsApp

🌐 Our Online Learning Platforms

Explore tutorials, notes, project guides and learning resources.

📺 YouTube Tutorials
Watch ICT & programming videos
💬 WhatsApp Community
Join our learning community
✍️ ICT Blog
Computer classes and tutorials
📰 WordPress
Notes and learning resources
📘 Facebook
Follow our official page
🌐 Wix Website
Explore our training services
💻 eTeacher Website
Online learning platform
📝 Medium
Read technology articles
❓ Quora
Project guidance and Q&A
🎓 Strikingly Portfolio
University project resources
🗣️ ElaKiri Forum
Join the project discussion
🎵 TikTok
Follow our learning videos
🛒 Payhip
Explore our digital resources
🌐 Weebly
Project and IT resources

ITClassSL — ICT Training | Computer Classes | Programming | University Project Guidance | Digital Marketing

Learn • Practice • Build • Grow 🚀