Current Affairs updated daily
KalviGavaniKalviGavani

Getting Started with Python — NCERT Class 11 Computer Science

Complete NCERT Solutions for CBSE Class 11 Computer Science Chapter 5 — all exercise questions on Python data types, operators, variables, input/output answered with working Python code.

Updated 11 June 20268 min read

Exercise Solutions Available

Step-by-step answers for all textbook questions in this chapter

View Solutions →

NCERT Solutions: Getting Started with Python — CBSE Class 11 Computer Science

This page provides complete NCERT exercise solutions for CBSE Class 11 Computer Science Chapter 5 — Getting Started with Python. Every question is answered with a clear explanation and working Python code.


How to Use These Solutions

1. Attempt the question yourself first — write the code on paper or in IDLE before reading the solution. 2. Compare your answer — check the logic, variable names, and output format against the solution. 3. Understand every line — do not copy blindly. If a line is unclear, revisit the [chapter guide](/class/11/computer-science/cbse-getting-started-python) for the concept. 4. Run the code — type each program in IDLE or any Python editor and verify the output. 5. Fix your mistakes — note where you went wrong in a mistake notebook before moving to the next question.


Key Concepts Quick Review

Before solving the exercises, make sure you recall these fundamentals:

ConceptKey Point
input()Always returns a string; use int() or float() for numbers
print()Use sep and end parameters; use f-strings for formatting
type()Returns the data type of a value or variable
Type conversionint(), float(), str(), bool() convert between types
Arithmetic/ = float division, // = floor division, % = remainder, ** = power
Comparison== != < > <= >= return True or False
Logicaland (both True), or (at least one True), not (reverse)
Assignment+= -= *= /= //= shorthand for updating variables
Precedence* > unary > / // % > + - > comparison > logical
Dynamic typingVariable type changes based on the value assigned

Exercise Solutions

Q1. Write a program to add two numbers and display the result.

# Program to add two numbers
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
result = num1 + num2
print(f"The sum of {num1} and {num2} is {result}")

Output:

Enter first number: 12 Enter second number: 8 The sum of 12.0 and 8.0 is 20.0

Q2. Write a program to find the area of a rectangle. Take length and breadth from the user.

# Program to find area of a rectangle
length = float(input("Enter length of rectangle: "))
breadth = float(input("Enter breadth of rectangle: "))
area = length * breadth
print(f"Area of rectangle = {area:.2f}")

Output:

Enter length of rectangle: 5.5 Enter breadth of rectangle: 3.2 Area of rectangle = 17.60

Q3. Write a program to convert temperature from Celsius to Fahrenheit.

The formula is: F = (C x 9/5) + 32

# Program to convert Celsius to Fahrenheit
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9 / 5) + 32
print(f"{celsius}°C = {fahrenheit:.2f}°F")

Output:

Enter temperature in Celsius: 37 37.0°C = 98.60°F

Q4. Write a program to swap two variables without using a third variable.

# Program to swap two variables without a temporary variable
a = int(input("Enter first number (a): "))
b = int(input("Enter second number (b): "))

print(f"Before swapping: a = {a}, b = {b}")

# Swapping using arithmetic
a = a + b
b = a - b
a = a - b

print(f"After swapping: a = {a}, b = {b}")

Output:

Enter first number (a): 10 Enter second number (b): 25 Before swapping: a = 10, b = 25 After swapping: a = 25, b = 10

Alternative method using Python's multiple assignment:

a = int(input("Enter a: "))
b = int(input("Enter b: "))
a, b = b, a
print(f"After swap: a = {a}, b = {b}")

Q5. Write a program to find the data type of a value entered by the user.

# Program to find the data type of user input
value = input("Enter a value: ")
print(f"Input as string: {value}, type = {type(value)}")

# Try converting to int
try:
    int_value = int(value)
    print(f"As integer: {int_value}, type = {type(int_value)}")
except ValueError:
    print("Cannot convert to integer")

# Try converting to float
try:
    float_value = float(value)
    print(f"As float: {float_value}, type = {type(float_value)}")
except ValueError:
    print("Cannot convert to float")

Output (when user enters 42):

Enter a value: 42 Input as string: 42, type = <class 'str'> As integer: 42, type = <class 'int'> As float: 42.0, type = <class 'float'>

Q6. Write a program to demonstrate the use of arithmetic operators on two integers.

# Program to demonstrate arithmetic operators
a = int(input("Enter first integer: "))
b = int(input("Enter second integer: "))

print(f"{a} + {b} = {a + b}")
print(f"{a} - {b} = {a - b}")
print(f"{a} * {b} = {a * b}")
print(f"{a} / {b} = {a / b}")
print(f"{a} // {b} = {a // b}")
print(f"{a} % {b} = {a % b}")
print(f"{a} ** {b} = {a ** b}")

Output:

Enter first integer: 17 Enter second integer: 5 17 + 5 = 22 17 - 5 = 12 17 * 5 = 85 17 / 5 = 3.4 17 // 5 = 3 17 % 5 = 2 17 ** 5 = 1419857

Q7. Write a program that accepts the user's name and prints a personalised greeting.

# Program to accept name and print greeting
name = input("Enter your name: ")
print(f"Hello, {name}! Welcome to Python programming.")

Output:

Enter your name: Priya Hello, Priya! Welcome to Python programming.

Q8. Write a program to calculate simple interest.

The formula is: SI = (P x R x T) / 100

# Program to calculate simple interest
principal = float(input("Enter principal amount: "))
rate = float(input("Enter rate of interest (%): "))
time = float(input("Enter time (years): "))

simple_interest = (principal * rate * time) / 100
total_amount = principal + simple_interest

print(f"Simple Interest = {simple_interest:.2f}")
print(f"Total Amount = {total_amount:.2f}")

Output:

Enter principal amount: 10000 Enter rate of interest (%): 5 Enter time (years): 3 Simple Interest = 1500.00 Total Amount = 11500.00

Q9. Write a program to calculate the area and circumference of a circle.

# Program to calculate area and circumference of a circle
radius = float(input("Enter the radius of the circle: "))
pi = 3.14159

area = pi * radius ** 2
circumference = 2 * pi * radius

print(f"Area = {area:.2f}")
print(f"Circumference = {circumference:.2f}")

Output:

Enter the radius of the circle: 7 Area = 153.94 Circumference = 43.98

Q10. Write a program to accept two numbers and demonstrate relational operators.

# Program to demonstrate relational operators
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

print(f"{a} == {b} : {a == b}")
print(f"{a} != {b} : {a != b}")
print(f"{a} < {b}  : {a < b}")
print(f"{a} > {b}  : {a > b}")
print(f"{a} <= {b} : {a <= b}")
print(f"{a} >= {b} : {a >= b}")

Output:

Enter first number: 10 Enter second number: 20 10 == 20 : False 10 != 20 : True 10 < 20 : True 10 > 20 : False 10 <= 20 : True 10 >= 20 : False

Q11. Write a program to demonstrate logical operators.

# Program to demonstrate logical operators
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

print(f"({a} > 0) and ({b} > 0) : {(a > 0) and (b > 0)}")
print(f"({a} > 0) or ({b} > 0)  : {(a > 0) or (b > 0)}")
print(f"not({a} > 0)            : {not(a > 0)}")

Output:

Enter first number: 5 Enter second number: -3 (5 > 0) and (-3 > 0) : False (5 > 0) or (-3 > 0) : True not(5 > 0) : False

Q12. Write a program to evaluate an arithmetic expression and show operator precedence.

# Program to demonstrate operator precedence
a = int(input("Enter a: "))
b = int(input("Enter b: "))
c = int(input("Enter c: "))

result1 = a + b * c          # multiplication first
result2 = (a + b) * c       # parentheses override
result3 = a ** b + c         # exponentiation first
result4 = a + b // c         # floor division first

print(f"a + b * c   = {a} + {b} * {c} = {result1}")
print(f"(a + b) * c = ({a} + {b}) * {c} = {result2}")
print(f"a ** b + c  = {a} ** {b} + {c} = {result3}")
print(f"a + b // c  = {a} + {b} // {c} = {result4}")

Output:

Enter a: 2 Enter b: 3 Enter c: 4 a + b * c = 2 + 3 * 4 = 14 (a + b) * c = (2 + 3) * 4 = 20 a ** b + c = 2 ** 3 + 4 = 12 a + b // c = 2 + 3 // 4 = 2

Related Pages

  • [Getting Started with Python — Chapter Guide](/class/11/computer-science/cbse-getting-started-python)
  • [Flow of Control — Chapter Guide](/class/11/computer-science/cbse-flow-of-control)
  • [Flow of Control — Exercise Solutions](/class/11/computer-science/solutions/cbse-flow-of-control-exercise-solutions)

Frequently Asked Questions

This page has complete NCERT exercise solutions for CBSE Class 11 Computer Science Chapter 5 Getting Started with Python with working code.