དཔལ་ལྡན་འབྲུག་གཞུང་། ཤེས་རིག་དང་རིག་རྩལ་གོང་འཕེལ་ལྷན་ཁག།
Department of School Education
Ministry of Education & Skills Development
Python Coding
January 2024
Class IX ICT Curriculum
January 2024
PYTHON
Key stage IV
Class IX
© ICT Curriculum, MoESD
COMMENTS AND INPUT( )
Key Concept # 7
January 2024
PYTHON
Key stage IV
Class IX
© ICT Curriculum, MoESD
Concept Overview
Coding Concept | Sub - Concepts |
Comments & Input( ) |
|
January 2024
PYTHON
Key stage IV
Class IX
© ICT Curriculum, MoESD
Objectives
January 2024
PYTHON
Key stage IV
Class IX
© ICT Curriculum, MoESD
COMMENTS
ACTIVITIES
January 2024
PYTHON
Key stage IV
Class IX
Comments
January 2024
PYTHON
Key stage IV
Class IX
Benefits of Using Comments
Documentation
5
Gives Instruction guide in program
Debugging
4
Comments assist in debugging process
Collaboration
3
Helps team members to understand each other's code
Readability
2
Enhances the code readability
Code Explanation
1
Helps in adding note to explain the code.
Learning and Teaching
6
Makes it easier to understand the code
January 2024
PYTHON
Key stage IV
Class IX
Types of Comments
There are two types of comments:
Single line comment
Multi-line comment
Comments
1
2
January 2024
PYTHON
Key stage IV
Class IX
Single-line Comments
In the above example, the text “code below adds two numbers” is a single line comment as it is written after the # symbol and is also on the same line.
1 2 3 | #code below adds two numbers x,y= 4,5 print(x+y) |
Example
Single-line comments start with the # [Hash tag] symbol and everything after it on the same line is considered the comment.
Single-line comments are used for brief explanations on the same line as the code.
January 2024
PYTHON
Key stage IV
Class IX
Demo - Single-line Comments
1 2 3 4 5 6 7 | #variable name stores string value Sonam name = “Sonam” #variable age is assigned with the integer value 16 age = 16 #Displaying the values stored in the variables print(name) print(age) |
Code
1 2 | Sonam 16 |
Output
January 2024
PYTHON
Key stage IV
Class IX
Multi-line Comments
1 2 3 4 5 6 7 8 9 10 11 | ’’’The code below initialises variable x and y with the value 4 and 5 respectively. Lastly the sum of value stored in x and y variable is displayed using print function’’’ x = 4 y = 5 print(x+y) |
Example
Multi-line comments are enclosed within triple quotes (""") and can span across multiple lines.
Multi-line comments are often used for function or module documentation, explaining complex algorithms, or providing detailed insights into code functionality.
9 |
Output
January 2024
PYTHON
Key stage IV
Class IX
Demo 2 - Multi-line Comments
1 2 3 4 5 6 7 8 9 | ’’’The code below initialises variable name and age with the string value Sonam and integer value 5 respectively. In the following code, the value stored in these variables are displayed using print function’’’ name = “Sonam” age = 16 print(name) print(age) |
Code
Sonam 16 |
Output
January 2024
PYTHON
Key stage IV
Class IX
Activity 1 - Displaying Message
Write a Python program to display the message “ Gross National Happiness” and include a single-line comment that explains the purpose of the program.
1 2 | #Printing Gross National Happiness print("Gross National Happiness") |
Code
Gross National Happiness |
Output
January 2024
PYTHON
Key stage IV
Class IX
Activity 2 - Writing Single and Multi-line Comments
Write a Python program to welcome a student to coding. Include comments, both single-line and multiline to provide clear explanations of the program.
1 2 3 4 5 6 7 | ’’’Program to welcome students with their name and class to the world of coding.’’’ name = "Pema Khandu" #Store a person's name Class = IX #Store their grade print("Welcome to Python Programming!")#Greeting print("Name:",name) #Printing name print("Class:",Class) # Printing grade |
Code
Welcome to Python Programming! Name:Pema Khandu Class:9 |
Output
January 2024
PYTHON
Key stage IV
Class IX
INPUT FUNCTION
ACTIVITIES
January 2024
PYTHON
Key stage IV
Class IX
Input Function
January 2024
PYTHON
Key stage IV
Class IX
Input Function
1 2 | name = input(“Enter your Name:”) print(f’My name is {name}’) |
Example
Enter your Name: Sonam My name is Sonam |
Output
1 2 3 4 | num1 = int(input("Enter 1st No: ")) num2 = int(input("Enter 2nd No: ")) sum = num1 + num2 print(f"The Total is {sum}”) |
Example
Enter 1st No:34 Enter 2nd No:3 The Total is:37 |
Output
January 2024
PYTHON
Key stage IV
Class IX
Importance of input() function
Support basic user authentication, data validation, and dynamic behavior based on user input.
Facilitate the creation of interactive and dynamic Python programs.
Enable user input for various purposes, including data collection, user responses, and program customization.
Helps to gather information interactively from the user during program execution.
1
2
3
4
January 2024
PYTHON
Key stage IV
Class IX
Demo 1 - Entering Favourite Subject and Ambition
Write a Python program that asks the user to input their preferred subject and career ambition, stores the information in variables, and then prints the entered values.
1 2 3 4 | fav_subject = input(“enter your favourite subject”) ambition = input(“enter your ambition”) print(“Your favorite subject is ”,fav_subject) print(“Your career ambition is ”,ambition) |
Code
Your favorite subject is ICT Your career ambition is Data Analyst |
Output
January 2024
PYTHON
Key stage IV
Class IX
Activity 1 - Requesting For a Name
A Python program asks the users to enter their name and then displays the name on the screen.
1 2 3 | name = input('Please enter your name:') #let us assume that you have entered “Dechen” print(name) |
Code
Please enter your name: Dechen Dechen |
Output
January 2024
PYTHON
Key stage IV
Class IX
Activity 2 - Displaying Subject Marks
Write a Python program to ask the user to enter the marks of following subjects and display it accordingly:
January 2024
PYTHON
Key stage IV
Class IX
Activity 2 - Solution
1 2 3 3 4 5 6 7 | eng = input('Enter English mark: ') dzo = input('Enter Dzongkha mark: ') maths = input('Enter Maths mark: ') sci = input('Enter Science mark: ') hcg = input('Enter HCG mark: ') eco = input('Enter Economics mark: ') print('Your Marks are as follows: ') print(f“English: {eng}\n Dzongkha:{dzo}\n Maths: {maths}\n Science: {sci}\n HCG: {hcg}Economics: {eco}”) |
Code
Enter English mark: 89 Enter Dzongkha mark: 70 Enter Maths mark: 99 Enter Science mark: 89 Enter HCG mark: 89 Enter Economics mark: 90 Your Marks are as follows: English: 89 Dzongkha:70 Maths:99 Science: 89 HCG: 89 Economics: 90 |
Output
January 2024
PYTHON
Key stage IV
Class IX
Key Points
January 2024
PYTHON
Key stage IV
Class IX
Key Points
January 2024
PYTHON
Key stage IV
Class IX
བཀྲིན་ཆེ།
THANK YOU
January 2024
PYTHON
Key stage IV
Class IX