0% found this document useful (0 votes)
5 views12 pages

Class XI - Computer Science (Python)

The document is a lab manual for Class XI Computer Science, detailing various programming experiments. Each experiment includes an aim, algorithm, program code, and output examples, covering topics such as input/output, number comparison, pattern generation, mathematical series, and string manipulation. The manual serves as a practical guide for students to learn and implement basic programming concepts.
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)
5 views12 pages

Class XI - Computer Science (Python)

The document is a lab manual for Class XI Computer Science, detailing various programming experiments. Each experiment includes an aim, algorithm, program code, and output examples, covering topics such as input/output, number comparison, pattern generation, mathematical series, and string manipulation. The manual serves as a practical guide for students to learn and implement basic programming concepts.
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

Class XI (2025-26)

Subject Code: 083

Subject : Computer Science

Lab Manual

Experiment No. 1

Aim

To input a welcome message from the user and display it.

Algorithm

1.​ Start​

2.​ Input a welcome message​

3.​ Display the message​

4.​ Stop​

Program

msg = input("Enter a welcome message: ")

print("Welcome Message:", msg)

Output

Enter a welcome message: Hello Python

Welcome Message: Hello Python

Experiment No. 2
Aim

To input two numbers and display the larger and smaller number.

Algorithm

1.​ Start​

2.​ Read two numbers​

3.​ Compare them​

4.​ Display larger and smaller number​

5.​ Stop​

Program
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

print("Larger number:", max(a, b))


print("Smaller number:", min(a, b))

Output
Enter first number: 10
Enter second number: 5
Larger number: 10
Smaller number: 5

Experiment No. 3

Aim

To input three numbers and find the largest and smallest among them.

Program
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))

print("Largest number:", max(a, b, c))


print("Smallest number:", min(a, b, c))

Output
Enter first number: 10
Enter second number: 5
Enter third number: 2
Larger number: 10
Smaller number: 2

Experiment No. 4

Aim

To generate different patterns using nested loops.

Pattern–1

Program
for i in range(1, 6):
print("*" * i)

Output
*
**
***
****
*****

Pattern–2

Program
for i in range(5, 0, -1):
for j in range(1, i + 1):
print(j, end="")
print()

Output
12345
1234
123
12
1

Pattern–3

Program
for i in range(1, 6):
for j in range(i):
print(chr(65 + j), end="")
print()

Output
A
AB
ABC
ABCD
ABCDE

Experiment No. 5

Aim

To calculate the sum of different mathematical series.

(a) 1 + x + x² + ... + xⁿ
x = int(input("Enter x: "))
n = int(input("Enter n: "))

s = 0
for i in range(n + 1):
s += x ** i

print("Sum =", s)

(b) 1 − x + x² − x³ + ... ± xⁿ
x = int(input("Enter x: "))
n = int(input("Enter n: "))

s = 0
for i in range(n + 1):
s += (-1) ** i * (x ** i)

print("Sum =", s)

(c) x + x²/2 + x³/3 + ... + xⁿ/n


x = int(input("Enter x: "))
n = int(input("Enter n: "))

s = 0
for i in range(1, n + 1):
s += (x ** i) / i

print("Sum =", s)

(d) x + x²/2! + x³/3! + ... + xⁿ/n!


import math

x = int(input("Enter x: "))
n = int(input("Enter n: "))

s = 0
for i in range(1, n + 1):
s += (x ** i) / [Link](i)

print("Sum =", s)

Experiment No. 6

Aim

Determine whether a number is a perfect number, an Armstrong number or a palindrome.

Program
num = int(input("Enter a number: "))

if str(num) == str(num)[::-1]:
print("Palindrome Number")

temp = num
digits = len(str(num))
arm = 0
while temp > 0:
arm += (temp % 10) ** digits
temp //= 10

if arm == num:
print("Armstrong Number")

sum_div = 0
for i in range(1, num):
if num % i == 0:
sum_div += i

if sum_div == num:
print("Perfect Number")
Experiment No. 7

Aim

Input a number and check if the number is prime or composite number.

Program
num = int(input("Enter a number: "))

if num <= 1:
print("Neither prime nor composite")
else:
for i in range(2, num):
if num % i == 0:
print("Composite Number")
break
else:
print("Prime Number")

Experiment No. 8

Aim

Display the terms of a Fibonacci series.

Program
n = int(input("Enter number of terms: "))

a, b = 0, 1
for i in range(n):
print(a, end=" ")
a, b = b, a + b

Experiment No. 9
Aim

Compute the greatest common divisor and least common multiple of two integers.

Program
import math

a = int(input("Enter first number: "))


b = int(input("Enter second number: "))

gcd = [Link](a, b)
lcm = (a * b) // gcd

print("GCD =", gcd)


print("LCM =", lcm)

Experiment No. 10

Aim

Count and display the number of vowels, consonants, uppercase, lowercase characters in
string.

Program
s = input("Enter a string: ")

vowels = consonants = upper = lower = 0

for ch in s:
if [Link]():
upper += 1
if [Link]():
lower += 1
if [Link]() in "aeiou":
vowels += 1
elif [Link]():
consonants += 1
print("Vowels:", vowels)
print("Consonants:", consonants)
print("Uppercase:", upper)
print("Lowercase:", lower)

Experiment No. 11

Aim

Input a string and determine whether it is a palindrome or not; convert the case of characters in
a string.

Program
s = input("Enter a string: ")

if s == s[::-1]:
print("Palindrome String")
else:
print("Not a Palindrome")

print("Uppercase:", [Link]())
print("Lowercase:", [Link]())

Experiment No. 12

Aim

Find the largest/ smallest number in a list/tuple.

Program
lst = list(map(int, input("Enter list elements: ").split()))

print("Largest:", max(lst))
print("Smallest:", min(lst))

Experiment No. 13
Aim

Input a list of numbers and swap elements at the even location with the elements at the odd
location.

Program
lst = list(map(int, input("Enter list elements: ").split()))

for i in range(0, len(lst) - 1, 2):


lst[i], lst[i + 1] = lst[i + 1], lst[i]

print("After swapping:", lst)

Experiment No. 14

Aim

Input a list/tuple of elements, search for a given element in the list/tuple.

Program
lst = list(map(int, input("Enter elements: ").split()))
key = int(input("Enter element to search: "))

if key in lst:
print("Element found")
else:
print("Element not found")

Experiment No. 15
Aim

Create a dictionary with the roll number, name and marks of n students in a class and display
the names of students who have marks above 75.

Program
n = int(input("Enter number of students: "))
students = {}

for i in range(n):
roll = int(input("Enter roll number: "))
name = input("Enter name: ")
marks = int(input("Enter marks: "))
students[roll] = (name, marks)

print("Students scoring above 75:")


for roll, data in [Link]():
if data[1] > 75:
print(data[0])

Common questions

Powered by AI

User input in interactive programming provides flexibility and customization, enabling programs to process data dynamically based on the user's needs. In number evaluations, inputs allow users to test various scenarios like distinguishing between prime and composite numbers, or calculating GCD and LCM, making the program adaptable for different cases. Similarly, for string evaluations, user inputs facilitate operations like palindrome checks or character counts, tailoring outputs based on diverse string inputs. This interaction not only personalizes user experience but also demonstrates practical applications of computational concepts .

Classifying numbers by properties such as perfect, Armstrong, or palindromic in introductory programming courses offers significant educational benefits. These classifications encourage students to explore fundamental concepts like loops, conditionals, and mathematical operations, enhancing their problem-solving skills and understanding of number theory. These exercises provide a concrete and engaging way to apply theoretical knowledge to practical problems, fostering an appreciation for the underlying mathematics in programming. It also teaches algorithmic thinking by prompting students to develop step-by-step solutions to verify these properties, aligning with real-world computational tasks .

The objective of using nested loops in pattern generation is to create structured outputs that adhere to specified formats or requirements. Different patterns are achieved by adjusting the loops' range and logic. For example, for Pattern-1, a single loop with a range from 1 to 5 is used where the print statement multiplies a character by the loop index, resulting in an increasing number of stars per line. In Pattern-2, a nested loop structure is utilized, where the outer loop decrements from 5 to 1, controlling the lines, and the inner loop prints numbers from 1 up to the current index of the outer loop, forming a triangular pattern of numbers. Pattern-3 again uses nested loops, but the outer loop controls the lines from 1 to 5, and the inner loop prints alphabets increasing from 'A' with each line, creating an alphabetic cascading pattern .

Swapping elements at even and odd positions in a list demonstrates the application of computational logic and algorithm design by employing index manipulation techniques. The implementation uses a loop to iterate over the list while accessing adjacent pairs and swapping them using a temporary variable. This process showcases foundational concepts such as indexing, list iteration, and in-place data manipulation, which are pivotal for performing optimized operations on data structures. It highlights both the iterative nature of algorithms and the logical steps needed to alter data organization, crucial for developing efficient software solutions .

Patterns are a practical tool in learning programming as they vividly illustrate the use of control structures and loop mechanisms. Constructing patterns such as nested star patterns or pyramid numbers requires students to understand and manipulate nested loops, conditional statements, and variable scopes. Through repetitive pattern creation exercises, learners explore the mechanics of iteration, block structure, and execution flow, which are foundational concepts for mastering more complex programming tasks. These exercises build problem-solving skills and reinforce logical thinking necessary for effective coding .

Evaluating numbers for characteristics like being palindromes, Armstrong, or perfect numbers helps in understanding special properties that numbers can exhibit, which are of interest in number theory and applications. A palindrome number reads the same forward and backward, highlighting symmetrical properties. An Armstrong number equals the sum of its digits each raised to the power of the number of digits, showcasing unique number digit relationships. A perfect number is equal to the sum of its proper divisors, indicating a balance between the number and its components. Such evaluations illustrate diverse number properties and their potential applications in cryptography, mathematical puzzles, and algorithm development .

Mathematical series in programming are implemented to compute sums with defined mathematical rules. The main variations include geometric series, alternating series, and series involving divisions and factorials. For instance, in Experiment No. 5(a), a geometric series is computed using a simple loop that raises x to successive powers up to n, summing each term. In (b), an alternating series involves multiplying terms by (-1)^i to alternate signs. Series (c) and (d) add complexity by incorporating divisions and factorials respectively, where each term involves dividing by the current index or its factorial, adding layers of computational complexity .

To determine whether a number is prime or composite, the program checks if the number is greater than 1, as numbers less than or equal to 1 are neither. It then iteratively tests divisibility from 2 up to the number minus one. A number divisible by any of these is considered composite; otherwise, it is prime. Identifying prime numbers is crucial as they serve as fundamental building blocks in arithmetic, with applications in cryptography where the difficulty of factoring large composite numbers into primes enhances security .

Python's inbuilt functions, such as `math.gcd()` for finding the greatest common divisor (GCD), streamline numerical processing by encapsulating complex logic within a simple function call, enhancing developer efficiency and code readability. Similarly, calculating the least common multiple (LCM) using the relationship LCM(a, b) = (a * b) // GCD(a, b) leverages these functions to efficiently compute results. These inbuilt capabilities reduce error rates and execution time, promoting effective algorithm implementation in mathematical contexts where precision and speed are essential .

Understanding numerical series helps optimize algorithmic efficiency by allowing developers to recognize patterns and apply formulas that reduce computational complexity. For instance, knowing that a series like 1 + x + x² + ... + xⁿ can be directly calculated using the formula for the sum of a geometric series avoids iterative summation, improving performance. Similarly, alternating series or series involving factorials (as seen in the experiments) introduce handling different aspects of computation, providing insights into managing precision, computational limits, and resource usage effectively. Such knowledge is pivotal in high-performance computing and real-time application contexts .

You might also like