Informatics Practices

Python Statements, Comments, Input Output, Data Type Conversion and Debugging | Complete Notes | CBSE Class 11 Informatics Practices (2026–27)

Class 11 · Informatics Practices

Python Statements, Comments, Input Output, Data Type Conversion and Debugging

A Python program is made up of statements that instruct the computer to perform specific tasks. While writing programs, it is equally important to make the code readable using comments, interact with users using input and output statements, convert data from one type to another, and identify and correct errors through debugging. These concepts form the foundation of Python programming and are essential for developing efficient and error-free programs.


Learning Outcomes

After studying this chapter, you will be able to:

  • Understand Python statements and their types.
  • Write single-line and multi-line comments.
  • Use print() and input() functions effectively.
  • Display formatted output.
  • Perform explicit data type conversion.
  • Identify different types of programming errors.
  • Debug Python programs efficiently.

What is a Statement?

Definition

A statement is an instruction written in Python that tells the computer to perform a particular task.

Every Python program consists of one or more statements. Python executes these statements one after another in the order in which they appear unless control statements change the flow of execution.

Example

print("Welcome to Python")
x = 10
y = 20
print(x + y)

In the above program, each line is a separate Python statement.


Types of Statements

The commonly used statements in Python include:

Statement Purpose
Assignment Statement Assigns a value to a variable.
Expression Statement Performs calculations or evaluates expressions.
Input Statement Accepts data from the user.
Output Statement Displays information on the screen.

Assignment Statement

An assignment statement stores a value in a variable using the assignment operator (=).

Syntax

variable = value

Example

name = "Aarav"
age = 16
marks = 92.5

Expression Statement

An expression statement performs calculations or evaluates expressions.

Example

a = 15
b = 5

print(a + b)
print(a * b)
print(a / b)

Output

20
75
3.0

Comments in Python

Definition

Comments are explanatory notes written within a program. They improve the readability of the code and are ignored by the Python interpreter during execution.


Why are Comments Important?

  • Improve program readability.
  • Explain the purpose of code.
  • Help during debugging.
  • Make teamwork easier.
  • Simplify future modifications.

Single-Line Comments

A single-line comment begins with the # symbol.

Example

# Display welcome message
print("Welcome to CodeStep Academy")

Multi-Line Comments

Python does not have a separate syntax for multi-line comments. Triple quotes are commonly used to write documentation or multi-line descriptions.

Example

"""
This program
calculates
the average marks.
"""

Input and Output Statements

Python interacts with users through input and output statements.

  • input() accepts data from the user.
  • print() displays data on the screen.

The print() Function

Definition

The print() function is used to display information on the screen.

Syntax

print(value)

Example

print("Hello Students")
print(125)
print(95.6)

Output

Hello Students
125
95.6

Printing Multiple Values

name = "Aditi"
marks = 94

print(name, marks)

Output

Aditi 94

The sep Parameter

The sep parameter specifies the separator between multiple values.

Example

print("2026","07","25",sep="-")

Output

2026-07-25

The end Parameter

The end parameter changes the default line ending.

Example

print("Python",end=" ")
print("Programming")

Output

Python Programming

The input() Function

Definition

The input() function accepts data entered by the user through the keyboard.

Syntax

variable = input("Message")

Example

name = input("Enter your name : ")
print("Welcome",name)

Sample Output

Enter your name : Riya
Welcome Riya

Important Note About input()

Remember

The input() function always returns the entered value as a string (str), even if the user enters a number.

Example

age = input("Enter age : ")
print(type(age))

Output

<class 'str'>

Real-Life Example

A school management system asks a student to enter their name, class, and roll number before displaying the information on the screen.

name = input("Enter Name : ")
class_name = input("Enter Class : ")
roll = input("Enter Roll Number : ")

print("Student Details")
print(name)
print(class_name)
print(roll)

Sample Output

Enter Name : Aarav
Enter Class : XI
Enter Roll Number : 15

Student Details
Aarav
XI
15

Common Mistakes While Using input() and print()

Mistake Correct Practice
Assuming input() returns an integer. It always returns a string unless converted.
Forgetting quotation marks around text. Always enclose strings in quotes.
Using print without parentheses. Always write print().
Using commas inside mathematical expressions. Use operators such as +, -, *, / instead.


Data Type Conversion

Sometimes, while writing Python programs, we need to convert data from one data type to another. This process is known as data type conversion or type casting.

Definition

Data type conversion is the process of converting a value from one data type to another so that it can be used correctly in a program.


Types of Data Type Conversion

Type Description
Implicit Conversion Performed automatically by Python.
Explicit Conversion Performed manually by the programmer using conversion functions.

Implicit Data Type Conversion

Python automatically converts one data type into another whenever required to avoid data loss. This is called implicit type conversion.

Example

a = 15
b = 4.5

c = a + b

print(c)
print(type(c))

Output

19.5
<class 'float'>

Since one operand is a float, Python automatically converts the integer value to a float before performing the addition.


Explicit Data Type Conversion

Sometimes Python cannot convert data automatically. In such cases, the programmer uses built-in conversion functions. This process is called explicit type conversion.


The int() Function

The int() function converts a value into an integer.

Example

x = "25"

y = int(x)

print(y)
print(type(y))

Output

25
<class 'int'>

The float() Function

The float() function converts a value into a floating-point number.

Example

x = "75"

y = float(x)

print(y)
print(type(y))

Output

75.0
<class 'float'>

The str() Function

The str() function converts a value into a string.

Example

roll = 18

student = str(roll)

print(student)
print(type(student))

Output

18
<class 'str'>

The bool() Function

The bool() function converts a value into a Boolean value (True or False).

Example

print(bool(10))
print(bool(0))
print(bool(""))
print(bool("Python"))

Output

True
False
False
True

Summary of Conversion Functions

Function Purpose Example
int() Converts to integer int("25")
float() Converts to float float("25")
str() Converts to string str(25)
bool() Converts to Boolean bool(0)

Debugging

Definition

Debugging is the process of identifying, locating, and correcting errors (bugs) in a program so that it executes correctly.

Even experienced programmers make mistakes. Debugging helps ensure that a program produces the expected output.


Types of Errors in Python

Errors in Python are generally classified into three categories:

  1. Syntax Errors
  2. Runtime Errors
  3. Logical Errors

1. Syntax Errors

A syntax error occurs when the rules (syntax) of the Python language are violated.

Example

print("Welcome"

Error: Missing closing parenthesis.


2. Runtime Errors

A runtime error occurs while the program is executing. The program starts successfully but stops because of an invalid operation.

Example

a = 20
b = 0

print(a / b)

Error: Division by zero (ZeroDivisionError).


3. Logical Errors

A logical error occurs when the program runs without any error but produces an incorrect result because of incorrect logic.

Example

length = 20
breadth = 10

area = 2 * (length + breadth)

print(area)

The program executes successfully, but the formula used calculates the perimeter instead of the area. Hence, the output is incorrect.


How to Debug a Program?

  • Read the error message carefully.
  • Check the line number mentioned in the error.
  • Verify the syntax of the statement.
  • Display intermediate values using print().
  • Test the program with different inputs.
  • Correct one error at a time.

Real-Life Example

Suppose a student enters marks using the input() function. Since input() returns a string, mathematical operations cannot be performed directly.

Incorrect Program

marks = input("Enter Marks : ")

print(marks + 5)

Result: The program raises a TypeError.

Correct Program

marks = int(input("Enter Marks : "))

print(marks + 5)

Common Errors

Mistake Correct Practice
Using input() directly for calculations. Convert the value using int() or float().
Misspelling Python keywords. Use correct spellings and proper case.
Forgetting quotation marks around strings. Always enclose text within quotes.
Ignoring indentation. Maintain proper indentation throughout the program.
Using the wrong formula. Verify the program logic before execution.

Quick Revision

Concept Remember
Statement An instruction executed by Python.
Comment Improves readability and is ignored during execution.
print() Displays output on the screen.
input() Accepts input from the user and returns a string.
Implicit Conversion Performed automatically by Python.
Explicit Conversion Performed using conversion functions.
Debugging Process of finding and correcting errors.
Syntax Error Violation of Python syntax rules.
Runtime Error Occurs during program execution.
Logical Error Program runs but produces incorrect output.

Important Points to Remember

  • Every Python program is made up of statements.
  • Comments improve code readability and maintenance.
  • print() displays output, whereas input() accepts user input.
  • input() always returns a string.
  • Use int(), float(), str(), and bool() for explicit data type conversion.
  • Debugging helps identify and correct errors in a program.
  • Syntax, runtime, and logical errors are the three most common types of programming errors.

CBSE Exam Tips

  • Remember that input() always returns a string.
  • Practice using conversion functions such as int() and float() before performing calculations.
  • Be able to differentiate between syntax, runtime, and logical errors with examples.
  • Use meaningful comments to improve the readability of programs.
  • Understand the purpose of the sep and end parameters of the print() function.
  • Practice writing small Python programs involving input, output, and data type conversion.

Summary

Python programs consist of statements that perform specific tasks. Comments make programs easier to understand, while the print() and input() functions enable interaction between the user and the computer. Data type conversion allows values to be converted from one type to another whenever required, and debugging helps programmers identify and correct errors. A clear understanding of these concepts enables students to write accurate, readable, and efficient Python programs, forming a strong foundation for advanced programming topics.