Sample CS Practical File XI
Sample CS Practical File XI
Sample CS Practical File XI
Practical File
Class XI (2021-2022)
Class: XI – A
Roll No: 19
1|Page
Index
S. Section Page
No. No.
1. Section-1: Basic Python Programs 3
2. Section-2: Programs using 8
different Datatypes
3. Section-3: If, Elif, Else 11
4. Section-4: For Loop 26
5. Section-5: While Loop 30
6. Section-6: Nested Loop 36
7. Section-7: Programs with for and 39
while Loop
8. Section-8: Programs related to 41
String Manipulation and String
Functions
9. Section-9: Lists 48
10. Section-10: Tuples 57
11. Section-11: Dictionaries 62
2|Page
Section-1: Basic Python Programs
About Python:
Python was created by Guido Van Rossum and first released in 1991.
It is:
❖ A high-level language
❖ Free and open source
❖ An interpreted language
❖ Easy to understand
❖ Case sensitive
❖ Portable & platform independent
❖ Rich library of predefined functions
❖ Helpful in web development
Python can be used in two modes, Interactive Mode and Script Mode. Also, it
supports Dynamic Typing.
The Python logo is composed of an iconic emblem with a wordmark on its right.
The emblem depicts a two-colored snake’s image, which was based on
the ancient Mayan drawings. The Python tricolor is a reflection of creativity and
professionalism; it also evokes a sense of confidence and stability.
There are numerous editors available for python. To name a few, Python IDLE,
Sublime Text Editor, Anaconda, PyCharm, Spyder, Jupyter, Visual Studio,
onlinegdb.com.
3|Page
Question 1:
Make a python program to calculate the number of years, then months and then
the left days using Python. For example, Input=400 days then year(s)= 1,
month(s)=3, day(s)=5
Code:
Output:
__________________________________________________________________________________
Question 2:
Code:
Output:
4|Page
Question 3:
Code:
Output:
Question 4:
Code:
Output:
5|Page
Question 5:
Code:
Output:
Question 6:
Gurukul Vidyapeeth is a reputed institution in the field of academic and extra-
curricular activities. Every year, with the commencement of the new session at
high speed by 10% for all the students which was manually done till date and
required enormous effort on the part of the office staff. To solve this problem,
develop a Python program that calculates this 10% fee Hike every year
automatically after obtaining the basic fee amount from the user and displays it
to the parents of the students enrolled with the institute.
Code:
Output:
6|Page
Question 7:
Make a python program to calculate the solution/roots of a quadratic equation
using the quadratic formula taking inputs as the coefficients a, b, c of the
general quadratic equation ax2+bx+c=0.
Code:
Output:
7|Page
Section-2: Programs using different Datatypes
Data can be of many types. For example, character, integer, real, string etc.
Anything enclosed in quotes represents string data in Python. Numbers with
fraction represent real data and True and False represent Boolean data.
Since the data to be dealt with are of many types, a programming language
must provide ways and facilities to handle all types of data.
1. Numbers:
• Integers
• Floating Point Numbers
• Complex Numbers
2. Strings
3. Compound data types:
• Lists
• Tuples
4. Sets
5. Dictionary
6. Mutable Types
7. Immutable Types
Hence, this section includes programs testing the knowledge regarding use of
different datatypes and type() function.
8|Page
Question 1: Make a python program to accept input of different datatypes and
display them and their datatypes
Code:
Output:
9|Page
Question 2: Make a python program to declare elements of different datatypes
and display their datatypes. Also, demonstrate the difference between sum and
concatenation.
Code:
Output:
10 | P a g e
Section-3: If, Elif, Else
What is It about?
The if..else statement evaluates test expression and will execute the body of if
only when the test condition is True.
The elif is short for else if. It allows us to check for multiple expressions.
If the condition for if is False, it checks the condition of the next elif block and so
on.
Only one block among the several if...elif...else blocks is executed according to
the condition.
The if block can have only one else block. But it can have multiple elif blocks.
11 | P a g e
Code:
Output:
Code:
Output:
12 | P a g e
Code:
Output:
Code:
Output:
13 | P a g e
Code:
Output:
Code:
Output:
14 | P a g e
Code:
15 | P a g e
Output:
Code:
Output:
16 | P a g e
Code:
Output:
17 | P a g e
Code:
18 | P a g e
Output:
19 | P a g e
Code:
Output:
Code:
Output:
20 | P a g e
Code:
Output:
21 | P a g e
Code:
Output:
22 | P a g e
Code:
Output:
23 | P a g e
Code:
Output:
24 | P a g e
Question 17:
Make a python program to calculate the electricity of bill
using the following data regarding rate of electricity for
Jodhpur Vidyut Nagar Nigam Ltd.
Code:
Output:
25 | P a g e
Section-4: For Loops
A for loop is used for iterating over a sequence (that is either a list, a tuple, a
dictionary, a set, or a string).
This is less like the for keyword in other programming languages, and works
more like an iterator method as found in other object-orientated programming
languages.
With the for loop we can execute a set of statements, once for each item in a
list, tuple, set etc.
26 | P a g e
Question 1: Write a program to accept an integer and print the multiplication
table of that number till 10 in the following format. Example: if number is 5
5 x 1 =5
5 x 2 = 10
5 x 3 = 15
5 x 10 = 50
Code:
Output:
27 | P a g e
Question 2: Write a program to accept the number of terms of the Fibonacci
series and print the series till that term. ie.,0 1 1 2 3 5 8 …………………………………………
Code:
Output:
Question 3: Write a program to input x and the number of terms and finds the
sum of series: 1 +x^2/2 + x^3/3 + … x^n/n.
Code:
Output:
28 | P a g e
Question 4: Write a program to find the sum of the series a, a + d, a + 2d, a + 3d,…
Code:
Output:
Question 5: Write a program to print the sum of the following series. Accept the value for ‘x’ and
the
number of terms of the series. 1 – 2x + 4x – 6x + ……nx
Code:
Output:
29 | P a g e
Section-5: While Loops
The while loop in Python is used to iterate over a block of code as long as the
test expression (condition) is true. We generally use this loop when we don't
know the number of times to iterate beforehand.
In the while loop, test expression is checked first. The body of the loop is
entered only if the test_expression evaluates to True. After one iteration, the
test expression is checked again. This process continues until the
test_expression evaluates to False.
The body starts with indentation and the first unindented line marks the end.
Python interprets any non-zero value as True. None and 0 are interpreted as
False.
30 | P a g e
Question 1: Write a program to accept an integer and check whether it is a prime
number or not and display proper messages.
Code:
Output:
31 | P a g e
Question 2: Write a program to accept an integer and display the reversed
integer (store the reversed number in a variable). Eg: If the number is 267 then
the reversed number is 762
Code:
Output:
Question 3: Write a program to accept an integer and display the factorial of that
number. Example: if the number is 3 then 3! is 6.
Code:
Output:
32 | P a g e
Question 4: Write a program to accept an integer and generate the divisors of
that integer. Example: If the number is 6 then its divisors are 1 2 3 6.
Code:
Output:
Question 5: Write a program to print first ‘n’ odd numbers in descending order.
Example: if n=5, then the output is 9 7 5 3 1
Code:
Output:
33 | P a g e
Question 6: Write a program to print the odd numbers occurring till the given
number in descending order. Example: if number=10, then the output is 9 7 5 3 1.
Code:
Output:
34 | P a g e
Question 7: Write a program to accept an integer and check whether it is
palindrome or not and display proper messages.
Code:
Method-1:
Method-2:
Output:
35 | P a g e
Section-6: Nested Loop
Question 1: Write a program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4!
+…….+ n/n!
Code:
Output:
36 | P a g e
Question 2: Write a program to print all prime numbers from 1 to ‘n’. Accept the
value for ‘n’ from the user. Eg: If number is 10, then the output is 2 3 5 7
Code:
Output:
Output:
37 | P a g e
Question 4: WAP to print:
4321
432
43
4
Code:
Output:
Code:
Output:
__________________________________________________________________________________
38 | P a g e
Section-5: Programs using both for and while
loop (2 Methods/Versions)
Question 1: Write a program to accept an integer and check whether it is an
Armstrong number or not and display proper messages.
Code:
Method-1:
Method-2:
Output:
39 | P a g e
Question 2: Write a program to accept an integer and find the sum of digits of
that number and display it
Code:
Method-1:
Method-2:
Output:
40 | P a g e
Section-6: String Manipulation & Functions
41 | P a g e
Question 1: WAP to use utility of all 5 basic string related functions without
actually using them.
Code:
42 | P a g e
Output:
43 | P a g e
Question 2: WAP to use/demonstrate utility of all 5 string related functions.
Code:
Output:
44 | P a g e
Question 3: WAP to check whether a string is palindrome or not.
Code:
Output:
Question 4: WAP to demonstrate the working and difference between find() and
index().
Code:
Output:
45 | P a g e
Question 5: WAP to print this if input is ‘ishan’:
‘IsHaN’
Code:
Output:
Code:
Output:
46 | P a g e
Question 7: WAP to demonstrate the working of all is __ () functions.
Code:
Output:
47 | P a g e
Lists
Lists are used to store multiple items in a single variable.
Lists are one of 4 built-in data types in Python used to store collections of data, the
other 3 are Tuple, Set, and Dictionary, all with different qualities and usage.
List Items:
List items are ordered, Mutable, and allow duplicate values.
List items are indexed, the first item has index [0], the second item has index [1] etc.
Mutable:
The list is mutable, meaning that we can change, add, and remove items in a list after it
has been created.
Allow Duplicates:
Since lists are indexed, lists can have items with the same value
List Length:
To determine how many items a list has, use the len() function
48 | P a g e
Question 1: Write a program to find the number of times an element occurs in the list.
Code:
Output:
49 | P a g e
Question 2: Write a program to read a list of n integers (positive as well as negative).
Create two new lists, one having all positive numbers and the other having all negative
numbers from the given list. Print all three lists.
Code:
Output:
50 | P a g e
Question 3: Write a function that returns the largest element of the list passed as
parameter.
Code:
Output:
Question 4: Write a function to delete the element of given value from the list. The
program should ask for the value of the element to be deleted from the list.
Code:
Output:
51 | P a g e
Question 5: Write a function to return the second largest number from a list of
numbers.
Code:
M-1:
M-2:
Output:
52 | P a g e
Question 6: Write a program to read a list of n integers and find their median.
Note: The median value of a list of values is the middle one when they are arranged in
order. If there are two middle values then take their average. Hint: You can use an built-
in function to sort the list.
Code:
Output:
53 | P a g e
Question 7: Write a program to read a list of elements. Modify this list so that it does
not contain any duplicate elements, i.e., all elements occurring multiple times in the list
should appear only once.
Code:
Output:
Question 8: Write a program to read a list of elements. Input an element from the user
that has to be inserted in the list. Also input the position at which it is to be inserted.
Write a user defined function to insert the element at the desired position in the list.
Code:
Output:
54 | P a g e
Question 9: Write a function to delete the element at the desired position in the list.
The program should ask for the position of the element to be deleted from the list.
Code:
M-1:
M-2:
Output:
55 | P a g e
Question 10: Read a list of n elements. Pass this list to a function which reverses this
list in-place without creating a new list.
Code:
M-1:
M-2:
M-3:
Output:
56 | P a g e
Tuples
Tuples are used to store multiple items in a single variable.
Tuple is one of 4 built-in data types in Python used to store collections of data, the
other 3 are List, Set, and Dictionary, all with different qualities and usage.
A tuple is a collection which is ordered and unchangeable. Tuples are written with
round brackets.
Tuple Items
Ordered
When we say that tuples are ordered, it means that the items have a defined order,
and that order will not change.
Unchangeable
Tuples are unchangeable, meaning that we cannot change, add or remove items
after the tuple has been created.
Allow Duplicates
Since tuples are indexed, they can have items with the same value
Tuple Length
To determine how many items a tuple has, use the len() function
57 | P a g e
Question 1: Write a program to input n numbers from the user. Store these
numbers in a tuple. Print the maximum and minimum number from this tuple.
Code:
Output:
58 | P a g e
Question 2: Write a program that inputs two tuples and creates a third, that
contains all elements of the first followed by all elements of the second.
Code:
Output:
Code:
(i) (ii)
Output:
(i)
(ii)
59 | P a g e
Question 4: Write a program that input two tuple seq_a and seq_b and print True if
every element in seq_a is also an element of seq_b, else print False.
Code:
Output:
Question 5: Write a python program which takes as input, a tuple T and returns the
second largest element in the tuple.
Code:
Output:
Output:
60 | P a g e
Question 7: A tuple stores marks of a student in five subjects. Avg. Grade
Write a program to calculate the grade of the student as per the
>=75 'A'
following:
60 – 74.99 'B'
Code:
50- 50.99 'C'
<50 'D'
Output:
Question 8: A tuple stores Admission number, Name and marks of a student in five
subjects. Write a program to calculate the grade of the student as per the criteria
given above.
Code:
Output:
61 | P a g e
Dictionaries
Dictionaries are used to store data values in key:value pairs.
A dictionary is a collection which is ordered*, changeable and do not allow
duplicates.
Dictionaries are written with curly brackets, and have keys and values
Dictionary Items
Dictionary items are ordered, changeable, and does not allow duplicates.
Dictionary items are presented in key:value pairs, and can be referred to by using the
key name.
Ordered or Unordered?
As of Python version 3.7, dictionaries are ordered. In Python 3.6 and earlier,
dictionaries are unordered.
When we say that dictionaries are ordered, it means that the items have a defined
order, and that order will not change.
Unordered means that the items does not have a defined order, you cannot refer to
an item by using an index.
Changeable
Dictionaries are changeable, meaning that we can change, add or remove items after
the dictionary has been created.
Dictionary Length
To determine how many items a dictionary has, use the len() function
62 | P a g e
Question 1: Write a Python program to find the highest 2 values in a dictionary.
Code:
Output:
Question 2: WAP to create a dictionary from a string. Track the count of the letters
of string. Sample: 'w3resource' Expected output: {'3': 1, 's': 1, 'r': 2, 'u': 1, 'w': 1, 'c': 1,
'e': 2, 'o': 1}
Code:
Output:
63 | P a g e
Question 3: Write Python script to input country name and its capital of 5 countries.
Add them to a dictionary and also display it.
Code:
Output:
64 | P a g e
Question 4: Write Python script to create a dictionary with famous monuments and
their location. Input name of any monument and check whether that monument is
present in the dictionary or not. If the monument is not present in the dictionary
then add it to the dictionary.
Code:
Output:
65 | P a g e
Question 5: WAP that repeatedly asks user to enter product names and prices. Store
all of these in a dictionary whose keys are the product names and whose values are
the qty, price and discount. When the user is done entering products and record,
allow them to repeatedly enter a product name and print the corresponding price or
a message if the product is not in the dictionary.
Prod={‘Keyboard’:[10,500,10],’Mouse’:[5,450,5]}
Code:
Output:
66 | P a g e