**Computer Science Class 11 Practical – **Practical work is an important aspect of learning computer science. It allows students to apply theoretical concepts to real-world problems and develop hands-on experience. In a computer science class 11, practical work may include programming assignments and projects that use various programming languages and tools.

**Contents**show

## Computer Science Class 11 Practical

##### Q. Input a welcome message and display it

`print("Welcome to the program")`

**Output **

Welcome to the program

##### Q. Input two numbers and display the larger / smaller number

```
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print("Larger number: ", max(num1, num2))
print("Smaller number: ", min(num1, num2))
```

**Output**

Enter first number: 55

Enter second number: 33

Larger number: 55

Smaller number: 33

##### Q. Input three numbers and display the largest / smallest number

```
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
num3 = int(input("Enter third number: "))
print("Largest number: ", max(num1, num2, num3))
print("Smallest number: ", min(num1, num2, num3))
```

**Output**

Enter first number: 52

Enter second number: 66

Enter third number: 44

Largest number: 66

Smallest number: 44

##### Q. Generate the following patterns using nested loop.

**a) *
**
***
****
*******
for i in range(1, 6):
print("*" * i)
**b) 1 2 3 4 5
1 2 3 4
1 2 3
1 2
1**
for i in range(5, 0, -1):
print(" ".join([str(x) for x in range(1, i + 1)]))
**c) A
AB
ABC
ABCD
ABCDE**
for i in range(1, 6):
print("".join([chr(x) for x in range(65, 65 + i)]))

##### Q. Write a program to input the value of x and n and print the sum of the following series:

**a) 1+x+x2+x3+x4+. ..........xn**
def sum_of_series(x, n):
result = 0
for i in range(n + 1):
result += x**i
return result
x = int(input("Enter the value of x: "))
n = int(input("Enter the value of n: "))
print("Sum of the series:", sum_of_series(x, n))
**Output**
Enter the value of x: 5
Enter the value of n: 10
Sum of the series: 12207031
**b) 1-x+x2-x3+x4 .................................xn**
def sum_of_series(x, n):
result = 0
for i in range(n + 1):
result += (-1)**i * x**i
return result
x = int(input("Enter the value of x: "))
n = int(input("Enter the value of n: "))
print("Sum of the series:", sum_of_series(x, n))
**Output**
Enter the value of x: 5
Enter the value of n: 10
Sum of the series: 8138021

##### Q. Determine whether a number is a perfect number, an armstrong number or a palindrome

```
def is_perfect(num):
sum = 0
for i in range(1, num):
if num % i == 0:
sum += i
return sum == num
def is_armstrong(num):
temp = num
sum = 0
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
return sum == num
def is_palindrome(num):
return str(num) == str(num)[::-1]
num = int(input("Enter a number: "))
if is_perfect(num):
print(num, "is a perfect number")
elif is_armstrong(num):
print(num, "is an armstrong number")
elif is_palindrome(num):
print(num, "is a palindrome")
else:
print(num, "is none of the above")
```

**Output**

Enter a number: 66

66 is a palindrome

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

```
def is_prime(num):
if num > 1:
for i in range(2, num):
if (num % i) == 0:
return False
return True
else:
return False
num = int(input("Enter a number: "))
if is_prime(num):
print(num, "is a prime number")
else:
print(num, "is a composite number")
# Display the terms of a Fibonacci series
def fibonacci(n):
fib = [0, 1]
for i in range(2, n):
fib.append(fib[i-1] + fib[i-2])
return fib
n = int(input("Enter the number of terms: "))
print("Fibonacci series: ", fibonacci(n))
```

**Output**

Enter a number: 5

5 is a prime number

Enter the number of terms: 3

Fibonacci series: [0, 1, 1]

##### Q. Display the terms of a Fibonacci series.

```
def fibonacci(n):
if n <= 0:
return []
elif n == 1:
return [0]
elif n == 2:
return [0, 1]
else:
fib_list = [0, 1]
while len(fib_list) < n:
next_term = fib_list[-1] + fib_list[-2]
fib_list.append(next_term)
return fib_list
n = int(input("Enter the number of terms to display: "))
print("The terms of the Fibonacci series:", fibonacci(n))
```

**Output**

Enter the number of terms to display: 10

The terms of the Fibonacci series: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

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

```
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
def lcm(a, b):
return a * b // gcd(a, b)
a = int(input("Enter the first integer: "))
b = int(input("Enter the second integer: "))
gcd_value = gcd(a, b)
lcm_value = lcm(a, b)
print("The GCD of", a, "and", b, "is", gcd_value)
print("The LCM of", a, "and", b, "is", lcm_value)
```

**Output**

Enter the first integer: 18

Enter the second integer: 61

The GCD of 18 and 61 is 1

The LCM of 18 and 61 is 1098

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

```
def count_characters(string):
vowels = "AEIOUaeiou"
consonants = "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz"
uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lowercase = "abcdefghijklmnopqrstuvwxyz"
vowel_count = 0
consonant_count = 0
uppercase_count = 0
lowercase_count = 0
for char in string:
if char in vowels:
vowel_count += 1
elif char in consonants:
consonant_count += 1
elif char in uppercase:
uppercase_count += 1
elif char in lowercase:
lowercase_count += 1
return vowel_count, consonant_count, uppercase_count, lowercase_count
string = input("Enter a string: ")
vowel_count, consonant_count, uppercase_count, lowercase_count = count_characters(string)
print("Number of vowels:", vowel_count)
print("Number of consonants:", consonant_count)
print("Number of uppercase characters:", uppercase_count)
print("Number of lowercase characters:", lowercase_count)
```

**Output**

Enter a string: Welcome to my School

Number of vowels: 6

Number of consonants: 11

Number of uppercase characters: 2

Number of lowercase characters: 15

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

```
def is_palindrome(string):
return string == string[::-1]
def convert_case(string):
return string.swapcase()
string = input("Enter a string: ")
if is_palindrome(string):
print("The string is a palindrome.")
else:
print("The string is not a palindrome.")
converted_string = convert_case(string)
print("Converted string:", converted_string)
```

**Output**

Enter a string: MADAM

The string is a palindrome.

Converted string: madam

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

```
def find_min_max(numbers):
return min(numbers), max(numbers)
numbers = [int(num) for num in input("Enter a list of numbers separated by space: ").split()]
minimum, maximum = find_min_max(numbers)
print("The smallest number is:", minimum)
print("The largest number is:", maximum)
```

**Output**

Enter a list of numbers separated by space: 55 32 12

The smallest number is: 12

The largest number is: 55

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

```
def swap_elements(numbers):
for i in range(0, len(numbers) - 1, 2):
numbers[i], numbers[i + 1] = numbers[i + 1], numbers[i]
return numbers
numbers = [int(num) for num in input("Enter a list of numbers separated by space: ").split()]
swapped_numbers = swap_elements(numbers)
print("The list after swapping elements:", swapped_numbers)
```

**Output**

Enter a list of numbers separated by space: 55 41 63

The list after swapping elements: [41, 55, 63]

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

```
def search_element(elements, search_item):
if search_item in elements:
return True
else:
return False
elements = [int(num) for num in input("Enter a list of elements separated by space: ").split()]
search_item = int(input("Enter the item to search for: "))
if search_element(elements, search_item):
print("The item was found in the list/tuple.")
else:
print("The item was not found in the list/tuple.")
```

**Output**

Enter a list of elements separated by space: 61 24 52

Enter the item to search for: 24

The item was found in the list/tuple.

##### Q. Input a list of numbers and find the smallest and largest number from the list.

```
def find_min_max(numbers):
min_num = float('inf')
max_num = float('-inf')
for num in numbers:
if num < min_num:
min_num = num
if num > max_num:
max_num = num
return (min_num, max_num)
numbers = [int(x) for x in input("Enter a list of numbers separated by space: ").split()]
min_num, max_num = find_min_max(numbers)
print("Smallest number:", min_num)
print("Largest number:", max_num)
```

**Output**

Enter a list of numbers separated by space: 63 41 75

Smallest number: 41

Largest number: 75

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

```
n = int(input("Enter the number of students: "))
students = {}
for i in range(n):
roll_number = int(input("Enter the roll number: "))
name = input("Enter the name: ")
marks = int(input("Enter the marks: "))
students[roll_number] = (name, marks)
print("\nList of students who have scored marks above 75:")
for roll_number, (name, marks) in students.items():
if marks > 75:
print(name)
```

**Output**

Enter the number of students: 2

Enter the roll number: 1

Enter the name: Rakesh Kumar

Enter the marks: 88

Enter the roll number: 2

Enter the name: Amit Singh

Enter the marks: 58

List of students who have scored marks above 75:

Rakesh Kumar

##### Q. Write a program in python to find the area of Circle using If Conditions

```
import math
def area_of_circle(radius):
if radius < 0:
return "Invalid radius. Radius should be a positive number."
else:
area = math.pi * radius**2
return "Area of Circle with radius {} is {}".format(radius, area)
radius = float(input("Enter the radius of the circle: "))
print(area_of_circle(radius))
```

**Output**

Enter the radius of the circle: 6

Area of Circle with radius 6.0 is 113.09733552923255

##### Q. Write a program to take input from the user and print reverse order

```
def reverse_string(s):
return s[::-1]
string = input("Enter a string: ")
print("The reversed string is:", reverse_string(string))
```

**Output**

Enter a string: PYTHON

The reversed string is: NOHTYP

##### Q. Write a program to take two input from the user and concatenate the strings

```
def concatenate_strings(s1, s2):
return s1 + s2
string1 = input("Enter the first string: ")
string2 = input("Enter the second string: ")
print("The concatenated string is:", concatenate_strings(string1, string2))
```

**Output**

Enter the first string: My

Enter the second string: School

The concatenated string is: MySchool

##### Q. Write a program to accept list from the used and sort the list

```
def sort_list(lst):
return sorted(lst)
list = [int(x) for x in input("Enter a list of numbers separated by spaces: ").split()]
print("The sorted list is:", sort_list(list))
```

**Output**

Enter a list of numbers separated by spaces: 6 8 4 9 7 5

The sorted list is: [4, 5, 6, 7, 8, 9]

##### Q. Write a program to take input from the user and find the average of the list

```
def average_of_list(lst):
return sum(lst) / len(lst)
list = [int(x) for x in input("Enter a list of numbers separated by spaces: ").split()]
print("The average of the list is:", average_of_list(list))
```

**Output**

Enter a list of numbers separated by spaces: 6 5 1 8 4 9

The average of the list is: 5.5

##### Q. Write a program to take input from the used and find the largest and smallest number from the List

```
def largest_and_smallest_in_list(lst):
return max(lst), min(lst)
list = [int(x) for x in input("Enter a list of numbers separated by spaces: ").split()]
largest, smallest = largest_and_smallest_in_list(list)
print("The largest number in the list is:", largest)
print("The smallest number in the list is:", smallest)
```

**Output**

Enter a list of numbers separated by spaces: 6 5 7 1 5

The largest number in the list is: 7

The smallest number in the list is: 1

##### Computer Science Class 11 Notes

**Unit 1 : Basic Computer Organisation****Unit 1 : Encoding Schemes and Number System****Unit 2 : Introduction to problem solving****Unit 2 : Getting Started with Python****Unit 2 : Conditional statement and Iterative statements in Python****Unit 2 : Function in Python****Unit 2 : String in Python****Unit 2 : Lists in Python****Unit 2 : Tuples in Python****Unit 2 : Dictionary in Python****Unit 3 : Society, Law and Ethics**

##### Computer Science Class 11 MCQ

**Unit 1 : Basic Computer Organisation****Unit 1 : Encoding Schemes and Number System****Unit 2 : Introduction to problem solving****Unit 2 : Getting Started with Python****Unit 2 : Conditional statement and Iterative statements in Python****Unit 2 : Function in Python****Unit 2 : String in Python****Unit 2 : Lists in Python****Unit 2 : Tuples in Python****Unit 2 : Dictionary in Python****Unit 3 : Society, Law and Ethics**

##### Computer Science Class 11 NCERT Solutions

**Unit 1 : Basic Computer Organisation****Unit 1 : Encoding Schemes and Number System****Unit 2 : Introduction to problem solving****Unit 2 : Getting Started with Python****Unit 2 : Conditional statement and Iterative statements in Python****Unit 2 : Function in Python****Unit 2 : String in Python****Unit 2 : Lists in Python****Unit 2 : Tuples and Dictionary in Python****Unit 3 : Society, Law and Ethics**