Computer Science

Input and Output in Python Class 11 CBSE Computer Science: input(), print(), sep, end and Escape Sequences

Class 11 · Computer Science

Input and Output in Python (CBSE Class 11 Computer Science)

Every Python program interacts with the user by accepting input and displaying output. The input() function is used to receive data from the user, while the print() function displays information on the screen. Understanding these functions is essential for writing interactive Python programs.


Learning Objectives

  • Understand Input and Output.
  • Learn the input() function.
  • Learn the print() function.
  • Understand escape sequences.
  • Use sep and end parameters.
  • Display formatted output.

Input and Output


User
   │
   ▼
input()
   │
Process
   │
   ▼
print()
   │
   ▼
Output on Screen

Input Function

The input() function is used to accept data from the keyboard. Whatever the user enters is returned as a string.

Definition: The input() function accepts input from the user and returns it as a string.

Syntax


variable = input("Message")

Example 1


name = input("Enter your name: ")

print(name)

Sample Output


Enter your name: Aman

Aman

Example 2: Numeric Input


age = int(input("Enter your age: "))

print(age)

Since input() returns a string, int() converts it into an integer.


Output Function

The print() function displays messages, variables, and results on the screen.


Syntax


print(value1, value2, ...)

Example


name = "Riya"

marks = 95

print(name)

print(marks)

Output


Riya

95

Printing Multiple Values


name = "Riya"

marks = 95

print(name, marks)

Output


Riya 95

The sep Parameter

The sep parameter specifies the separator between multiple values printed by the print() function.

Syntax


print(value1, value2, sep="separator")

Example


print("Python", "CBSE", "Class 11", sep=" | ")

Output


Python | CBSE | Class 11

The end Parameter

By default, the print() function moves the cursor to the next line after displaying the output. The end parameter changes this behavior.

Syntax


print(value, end="...")

Example


print("Python", end=" ")

print("Programming")

Output


Python Programming

Escape Sequences

Escape sequences are special character combinations beginning with a backslash (\) that perform special functions while displaying output.

Escape Sequence Description
\nNew Line
\tHorizontal Tab
\\Backslash
\'Single Quote
\"Double Quote

Examples of Escape Sequences

New Line (\n)


print("Python\nProgramming")

Output


Python

Programming

Tab (\t)


print("Name\tMarks")

Output


Name    Marks

Printing Quotes


print("He said \"Hello\"")

Output


He said "Hello"

Formatted Output Using f-Strings

Python provides formatted string literals (f-strings) to insert variable values directly into a string. This feature is available in Python 3.6 and later.

Syntax


name = "Aman"

marks = 95

print(f"{name} scored {marks} marks.")

Output


Aman scored 95 marks.
CBSE Note: The official CBSE syllabus mentions accepting input and displaying output. While many schools now use Python 3.6+ where f-strings are supported, confirm with your teacher or school if a specific formatting style is expected in practical examinations.

Dry Run Example

Program


name = input("Enter Name: ")

age = int(input("Enter Age: "))

print(name, age)

Dry Run Table

Step Operation Value
1User enters NameAman
2Stored in name"Aman"
3User enters Age17
4int() converts to integer17
5print()Aman 17

Think Like a Programmer

Predict the output.


print("A", "B", "C", sep="-")

print("Python", end=" ")

print("Programming")
Click to View Answer

A-B-C

Python Programming

Output Prediction Challenge


name = "Riya"

marks = 92

print(name, marks, sep=" : ")

print("Result", end=" => ")

print("Pass")
Click to View Answer

Riya : 92

Result => Pass

Real-Life Example

Consider an ATM machine:

  • The ATM asks for your PIN → Input
  • The ATM processes your request.
  • The ATM displays your account balance → Output

Similarly, Python programs accept input, process it, and display output.


Common Beginner Mistakes

  • Forgetting that input() returns a string.
  • Not converting numeric input using int() or float().
  • Confusing sep and end.
  • Using incorrect escape sequences.
  • Missing quotation marks in print() statements.

Visual Memory Box

Function / Parameter Purpose
input()Accept user input
print()Display output
sepSeparator between values
endEnding character after output
\nNew line
\tHorizontal tab

Memory Trick

  • input() → Accept Data
  • print() → Display Data
  • sep → Separate Values
  • end → End of Output
  • \n → New Line
  • \t → Tab Space

Exam Tips

  • Remember that input() always returns a string.
  • Use int() or float() for numeric calculations.
  • Practice using sep and end.
  • Learn the commonly used escape sequences.
  • Know the syntax of both input() and print().

CBSE Important Questions

2 Marks

  1. Differentiate between input() and print().
  2. What is the purpose of the sep parameter?

3 Marks

  1. Explain escape sequences with suitable examples.
  2. Write a program to accept a student's name and marks and display them using sep.

5 Marks

  1. Explain the input() and print() functions with syntax, examples, escape sequences, and formatted output.

Practice Yourself

  1. Write a program to accept your name and city and display them.
  2. Write a program to accept two numbers and display their sum.
  3. Display a table using the \t escape sequence.
  4. Use sep to print values separated by a comma.
  5. Use end to print multiple words on the same line.

Frequently Asked Questions (FAQs)

1. What does the input() function return?

It always returns a string.

2. Which function is used to display output?

print().

3. What is the purpose of the sep parameter?

It specifies the separator between multiple values printed by print().

4. What is the default value of the end parameter?

The default value is \n (new line).

5. Which escape sequence inserts a new line?

\n.


Summary

  • input() accepts data from the user and returns it as a string.
  • print() displays output on the screen.
  • The sep parameter changes the separator between printed values.
  • The end parameter changes how a print() statement ends.
  • Escape sequences such as \n and \t help format output.
  • Input and output functions are used in almost every Python program.