0% found this document useful (0 votes)
6 views22 pages

Computer Science Practical File

The document contains a series of programming exercises for computer science students, focusing on string manipulation, list operations, and dictionary handling in Python. Each exercise includes a question, code section, and expected output. The tasks range from counting characters in strings to manipulating lists and creating dictionaries based on user input.

Uploaded by

adhdhyan.jain
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)
6 views22 pages

Computer Science Practical File

The document contains a series of programming exercises for computer science students, focusing on string manipulation, list operations, and dictionary handling in Python. Each exercise includes a question, code section, and expected output. The tasks range from counting characters in strings to manipulating lists and creating dictionaries based on user input.

Uploaded by

adhdhyan.jain
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

COMPUTER SCIENCE

PRACTICAL FILE
2
PROGRAM FILE

Q.1 Write a program to input any string and to count the


number of uppercase letters, lowercase letters, digits and
space characters.
CODE:

OUTPUT:​
Q.2 Write a program to input any string and to check whether
the given string is palindrome or not.

CODE:

OUTPUT:
Q.3 Write a program to input any string and to convert upper
case to lower case and vice- versa.

CODE:

OUTPUT:
Q.4 Write a program to input any string and to count the
number of times the word “book” exists in the string.

CODE:

OUTPUT:
Q.5 Write a program to input any string and to count all
vowels from the string.

CODE:

OUTPUT:
Q.6 Write a program to input any string and to create a list and
store all words first letter from the string.

CODE:​




OUTPUT:
Q.7 Write a program to input any list and to arrange all the
numbers in ascending order.

CODE:

OUTPUT:
Q.8 Write a program to input any list and implement the
following:
Input:[5,7,4,3,10]
Output:[7,4,3,10,5]
Move all elements and position front and keep the front
element at the end.

CODE:

OUTPUT:
Q.9 Write a program to input any list and implement the
following:
Input:[10,20,30,40,50,60]
Output:[20,10,40,30,60,50]
If the number is divisible by 10 then interchange with next
number

CODE:

OUTPUT:
Q.10 Move all elements and position front and keep the front
element at the end.
Input:[5,10,7,30,40,5]
Output:[5,7,10,40,30,5]
If the number is divisible by 10 then interchange with next
number

CODE:​

OUTPUT:
Q.11 Assuming that num is a list of integers, write code, display
the list. The code should then replace each element having
even value with its half and each element having odd value
with its double and then display the changed list. Example: if
the list has: 3,4,5,16,9 then the modified list should have:
6,2,10,8,18.

CODE:

OUTPUT:
Q.12 Write a program to create two equi-sized lists A and B
and then combine their contents into a third list C by
computing C[i]=2*A[i]+3*B[i] where value i varies from 0 to
n-1, n being the size of each list. Then display the lists A,B,C.

CODE:

OUTPUT:
Q.13 Write a program to read a list of n integers and find their
median.

CODE:

OUTPUT:
Q.14 Write a program to input a tuple and to find total and
average without using a function. Display all list numbers with
less value of average.

CODE:

OUTPUT:
Q.15 Write a program to input any number and to create a
dictionary based upon the following information.
Example: n=5 then d={1:1^3,2:2^3,3:3^3,4:4^3,5:5^3}

CODE:

OUTPUT:
Q.16 Write a program to input your friends’ names and their
phone no and store them
in the dictionary as the key-value pair. Perform the following
operations on the
dictionary:
(a) Display the name and Phone no. of all your friends in table
format
(b) Add a new key-value pair in this dictionary and display the
modified dictionary.
(c) Delete a particular friend from the dictionary.
(d) Modify the phone no of the existing friend.
(e) Check if a friend is present in the dictionary or not.
(f) Display the dictionary in sorted order of names.
CODE:​
OUTPUT:
Q.17 Write a program to input a string and create a string.
Note: Track the count of the letter. Ex: String: “w3resource”
Output: { ‘3’:1,’s’:1,’r’:1,’u’:1,’w’:1,’c’:1,’e’:2,’o’:1}

CODE:

OUTPUT:​
Q.18 Write a program to input a string and to convert it into a
dictionary. In the dictionary each word of string is a key and
number of letters is a value.

CODE:

OUTPUT:
Q.19 Write a program to create a third dictionary from two
dictionaries having some common keys, in such a way so that
the values of common keys are added in the third dictionary.
Input:{1:100,2:200,3:300}
Output: {1:400,2:400,3:300,5:500} {1:400,2:400,5:400}

CODE:​

OUTPUT:

You might also like