0% found this document useful (0 votes)
3 views16 pages

Python Print

The document provides an overview of output in Python, specifically focusing on the print() function and output formatting techniques. It explains the syntax of the print() function, demonstrates examples of printing various data types, and introduces methods for formatting output using comma operators, plus operators, and f-strings. Additionally, it includes activities for practical application of the concepts taught.

Uploaded by

vndmsn2rqh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views16 pages

Python Print

The document provides an overview of output in Python, specifically focusing on the print() function and output formatting techniques. It explains the syntax of the print() function, demonstrates examples of printing various data types, and introduces methods for formatting output using comma operators, plus operators, and f-strings. Additionally, it includes activities for practical application of the concepts taught.

Uploaded by

vndmsn2rqh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PYTHON Key stage IV Class IX

Key Concept # 5

OUTPUT

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Output

Output refers to information or a result produced by a computer after taking


an input, processing it, storing it, and displaying it as an output on the screen.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Print Function
In Python, print() function is used to display a specific message on a Python
console or terminal.
Syntax
print(object,sep="",end="")

1. Object is mandatory but sep and end parameters are optional.


2. If object is the string data type, it should be enclosed within single or
double quotes[" " OR ' '].

3. If an object is a variable name, there is no need to enclose it inside the


quotation mark.
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

Examples

Printing special
characters
Code: Printing
print(“=^ ^=”) numeric values

Output: Code:
=^ ^= print(2024) Printing text

Output: Code:
2024 print("Hello World!")
Output:
Hello World!

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Output Formatting

It refers to presenting the output in a desired format that is readable and


meaningful to the user.

In order to format the output, it is necessary to combine different values


and create the desired output.

Basic output formatting can be achieved by using the following:

1 2 3
Comma operator ( , ) Plus operator(+) F-strings( f’{}’ )

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Output Formatting (cont.)


Code

1 1 print(“Bhutan”,”India”,”USA”)

Output
Comma operator ( , )
Bhutan India USA
Separate multiple
objects to be Code
printed in the
same line 1 print(0, 1.1, -200, 3000)

Output

0 1.1 -200 3000


January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

Output Formatting (cont.)


Code -Example
2 1 print("Hello " + "Pema")
Output
Plus operator ( + )
Hello Pema
join or combine
more than one Code -Example
object or variable
1 print("Age: " + "17")
name(Concatenat
e strings) Output

Age: 17
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

Output Code -Example

Formatting (cont.) 1 score = 50


2 print(f’{score}points’)

Output
3
50 points
F-strings( f’{}’ )
Code -Example
add expressions
and variables 1 Name = "Pema"
directly into 2 print(f'Hello {Name}')
strings.
Output

Hello Pema
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

Demo 1 - Displaying Dorji’s five cousin name


Dorji has five cousin brothers namely Karma Tshering, Pema Dorji, Kummar
Galay, Tshewang Tenzin and Samphel Rabten. Write a Python program to
display the names of all the cousin brothers of Dorji.
Code Output
1 print(‘*************') *************
2 print(' Cousin ') Cousin
3 print('*************') *************
4 print('Karma Tshering') Karma Tshering
5 print('Pema Tshering') Pema Tshering
6 print('Kummar Galay') Kummar Galay
7 print('Tshewang Tenzin') Tshewang Tenzin
8 print('Samphel Rabten') Samphel Rabten
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

Activity 1 - Printing Kuzuzangpo La and Tree

1. Write a Python program to print 1


Code
“Kuzuzangpo La”.
1 print('Kuzuzangpo La')
2. Write a Python program to print a
cypress tree pattern as shown below.
2
Code
1 print(' *')
2 print(' ***')
3 print(' *****')
4 print(' *******')
5 print(' | |')

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 2 - Printing Output


Copy the code in your notebook and write the output for each.

1 Code 2 Code

1 name=”Pema” 1 print("Hello", "how are


2 age=16 you?")
3 print(f'My name is
{name} and I am {age} Output
years old.') Hello how are you? 2

Output 1
My name is Pema and I am 16 years old.
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

Activity 3 - Creating a man with Signboard

Write a Python
program to create a
robot holding a
signboard with
‘Kuzuzangpo la’
message displayed on
it.

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 3 Solution
Code
1 print(' \||||||||||/ ')
2 print(' 0 0 ')
3 print(' ___oo0_____( )____________')
4 print('| |')
5 print('| |')
6 print('| "Kuzuzangpo la" |')
7 print('| |')
8 print('|__________________oo0____|')
9 print(' | | | |')
10 print(' | | | |')
11 print(' o0|_| |_|0o')

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 4 - Displaying Student Biodata


Write a Python program to display a students Biodata.

Code

1 print(“Name: Rigzin Samdrup”)


2 print(“Age: 20”)
3 print(“DOB: 04/04/2021”)
4 print(“Class: IX”)
5 print(“School: Mongar Higher Secondary School”)
6 print(“Dzongkhag: Mongar”)

January 2024 © ICT Curriculum, MoESD


PYTHON Key stage IV Class IX

Activity 5 - Test your understanding.


Answer the following questions by selecting the best answer from
the four options given.
1. What is the primary purpose of the print() function in Python?
A) Define a new variable
B) Input data from the user
C) Mathematical calculations
D) Display output to the console

2. Which of the following statements is used for printing multiple values on


the same line in Python?
A) print(value1; value2)
B) print(value1, value2)
C) print(value1 + value2)
D) print(value1 \n value2)
January 2024 © ICT Curriculum, MoESD
PYTHON Key stage IV Class IX

Key Points

● print() function can be used to display a specific message on a Python


console or terminal.
● Output formatting can be used to present the output in a desired format
that is readable and meaningful to the user
● We can print multiple values on the same line using comma separator.
● F-string can be used to format expressions within strings.
● Plus operator ( + ) can be used to display output by concatenating
strings.

January 2024 © ICT Curriculum, MoESD

You might also like