1 of 25

དཔལ་ལྡན་འབྲུག་གཞུང་། ཤེས་རིག་དང་རིག་རྩལ་གོང་འཕེལ་ལྷན་ཁག།

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

2 of 25

COMMENTS AND INPUT( )

Key Concept # 7

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

3 of 25

Concept Overview

Coding Concept

Sub - Concepts

Comments & Input( )

  • Comments
  • Single line comment
  • Multi-line comment
  • Input function

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

4 of 25

  • Explain comments with examples.
  • Differentiate between single-line and multi-line comments.
  • Explain the benefits of using comments for effective coding.
  • Write comments in Python programs to enhance code readability.
  • Define input function with example.
  • Explain the purpose of the input( ) function.
  • Create interactive programs using input() function.

Objectives

January 2024

PYTHON

Key stage IV

Class IX

© ICT Curriculum, MoESD

5 of 25

COMMENTS

ACTIVITIES

  1. Understanding Comments
  2. Demo 1 - Single Comments
  3. Demo 2- Multi-line Comments
  4. Activity 1 - Displaying Message
  5. Activity 2 - Writing Single and Multi-line Comments

January 2024

PYTHON

Key stage IV

Class IX

6 of 25

Comments

  • Comments in coding are lines of text added to explain what the code does.
  • Comments are not executed as part of the program; they are for human readers.
  • Comments make the code easier to understand by providing explanations, notes, or reminders.
  • Comments help other programmers who might need to work with the code later.
  • Comments are like little messages written directly into the code for better comprehension.

January 2024

PYTHON

Key stage IV

Class IX

7 of 25

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

8 of 25

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

9 of 25

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

10 of 25

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

11 of 25

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

12 of 25

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

13 of 25

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

14 of 25

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

15 of 25

INPUT FUNCTION

ACTIVITIES

  1. Understanding Input Function
  2. Demo 1 - Entering Favourite Subject and Ambition
  3. Activity 1 - Requesting for a Name
  4. Activity 2 - Displaying Subject Marks

January 2024

PYTHON

Key stage IV

Class IX

16 of 25

Input Function

  • input() function is used to get information from the user while the program is running.
  • You can ask the user for different types of information, like their name or age.
  • Whatever the user types is stored as text (string data type), even if it looks like a number or some other data.
  • input() function works by displaying a message to the user, then waiting for them to type something and press Enter.

January 2024

PYTHON

Key stage IV

Class IX

17 of 25

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

18 of 25

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

19 of 25

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

20 of 25

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. Write the solution in your notebook for the above program.
  2. Test the codes in the Python IDLE.
  3. Make changes to the code if there are errors(debugging).

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

21 of 25

Activity 2 - Displaying Subject Marks

Write a Python program to ask the user to enter the marks of following subjects and display it accordingly:

  • English
  • Dzongkha
  • Maths
  • Science
  • HCG
  • Economics

January 2024

PYTHON

Key stage IV

Class IX

22 of 25

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

23 of 25

  • Comments are used to provide explanations to the code for better understanding.
  • Single-line comments are for brief remarks on a single line that begins with # symbol.
  • Multi-line comments are enclosed within triple quotes (""") and can span across multiple lines.
  • Comments are not executed as part of the program; they are for human readers.
  • Comments facilitate collaboration among programmers, allowing for easier understanding of code written by others.

Key Points

January 2024

PYTHON

Key stage IV

Class IX

24 of 25

  • input() function is used to get information from the user while the program is running.
  • In input() function, whatever the user types is stored as text (string data type), even if it looks like a number or some other data.
  • input() function works by displaying a message to the user, then waiting for them to type something and press Enter.
  • We use the input() function in programming to interact with the user and collect data or information while the program is running.

Key Points

January 2024

PYTHON

Key stage IV

Class IX

25 of 25

བཀྲིན་ཆེ།

THANK YOU

January 2024

PYTHON

Key stage IV

Class IX