Computer Science File
Computer Science File
COMPUTER
SCIENCE
PRACTICAL
ANUJ GUPTA
XI-A
3
INDEX
S.NO PRACTICAL NO. DATE SIGN
1. Write a Python program to convert temperature in degree Celsius to degree Fahrenheit. If water boils at 20-07-23
100 degree C and freezes as 0 degree C, use the program to find out what is the boiling point and freezing
point of water on the Fahrenheit scale
2. Write a Python program to calculate the amount payable if money has been lent on simple interest. 20-07-23
Principal or money lent = P, Rate of interest = R% per annum and Time = T years. Then Simple Interest
(SI) = (P x R x T)/ 100. Amount payable = Principal + SI. P, R and T are given as input to the program.
3. Write a program to calculate in how many days a work will be completed by three persons A, B and C 20-07-23
together. A, B, C take x days, y days and z days respectively to do the job alone. The formula to calculate
the number of days if they work together is xyz/ (xy + yz + xz) days where x, y, and z are given as input to
the program.
4. Write a program to enter two integers and perform all arithmetic operations on them. 20-07-23
5. Write a program to swap two numbers using a third variable. 20-07-23
6. Write a program to swap two numbers without using a third variable. 20-07-23
7. Write a program to repeat the string ‘‘GOOD MORNING” n times. Here ‘n’ is an integer entered by the 20-07-23
user.
8. Write a program to find average of three numbers. 20-07-23
9. The volume of a sphere with radius r is 4/3πr3. Write a Python program to find the volume of spheres with 20-07-23
radius 7cm, 12cm, 16cm, respectively.
10. Write a program that asks the user to enter their name and age. Print a message addressed to the user that 20-07-23
tells the user the year in which they will turn 100 years old.
11. The formula E = mc2 states that the equivalent energy (E) can be calculated as the mass (m) multiplied by 20-07-23
the speed of light (c = about 3×108 m/s) squared. Write a program that accepts the mass of an object and
determines its energy.
12. . Presume that a ladder is put upright against a wall. Let variables length and angle store the length of the 20-07-23
ladder and the angle that it forms with the ground as it leans against the wall. Write a Python program to
compute the height reached by the ladder on the wall for the following values of length and angle: a) 16
feet and 75 degrees
13. Write a program that takes the name and age of the user as input and displays a message whether the user 20-07-23
is eligible to apply for a driving license or not. (The eligible age is 18 years).
14. Write a function to print the table of a given number. The number has to be entered by the user 27-07-23
15. Write a program that prints minimum and maximum of five numbers entered by the user. 27-07-23
16. Write a program to check if the year entered by the user is a leap year or not. 27-07-23
17. Write a program to generate the sequence: –5, 10, –15, 20, –25…. upto n, where n is an integer input by 27-07-23
the user.
18. Write a program to find the sum of 1+ 1/8 + 1/27......1/n3, where n is the number input by the user. 27-07-23
19. Write a program to find the sum of digits of an integer number, input by the user. 27-07-23
20. Write a function that checks whether an input number is a palindrome or not. 27-07-23
21. Write a program to print the following patterns: 27-07-23
22. Write a program to find the grade of a student when grades are allocated as given in the table below. 27-07-23
23. Write a program to input line(s) of text from the user until enter is pressed. Count the total number of 27-07-23
characters in the text (including white spaces),total number of alphabets, total number of digits, total
number of special symbols and total number of words in the given text. (Assume that each word is
separated by one space).
24. Write a user defined function to convert a string with more than one word into title case string where 16-08-23
string is passed as parameter. (Title case means that the first letter of each word is capitalised)
25. Write a function deleteChar() which takes two parameters one is a string and other is a character. The 16-08-23
function should create a new string after deleting all occurrences of the character from the string and
return the new string.
26. Input a string having some digits. Write a function to return the sum of digits present in this string. 16-08-23
27. Write a function that takes a sentence as an input parameter where each word in the sentence is separated 16-08-23
by a space. The function should replace each blank with a hyphen and then return the modified sentence.
28. Write a program to find the number of times an element occurs in the list. 3-10-23
29. Write a program to read a list of n integers (positiveas well as negative). Create two new lists, one having 3-10-23
2
all positive numbers and the other having all negative numbers from the given list. Print all three lists.
30. Write a function that returns the largest element of the list passed as parameter. 3-10-23
31. Write a function to return the second largest number from a list of numbers. 3-10-23
32 Write a program to read a list of n integers and find their median. 3-10-23
33. Write a program to read a list of elements. Modify this list so that it does not contain any duplicate 3-10-23
elements, i.e., all elements occurring multiple times in the list should appear only once.
34. Write a program to read a list of elements. Input an element from the user that has to be inserted in the list. 3-10-23
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.
35. Write a program to read elements of a list. a) The program should ask for the position of the element to be 3-10-23
deleted from the list. Write a function to delete the element at the desired position in the list. b) The
program should ask for the value of the element to be deleted from the list. Write a function to delete the
element of this value from the list.
36. Read a list of n elements. Pass this list to a function which reverses this list in-place without creating a 3-10-23
new list.
37. Write a program to read email IDs of n number of students and store them in a tuple. Create two new 20-10-23
tuples, one to store only the usernames from the email IDs and second to store domain names from the
email IDs. Print all three tuples at the end of the program
38. Write a program to input names of n students and store them in a tuple. Also, input a name from the user 20-10-23
and find if this student is present in the tuple or not, we can accomplish these by: writing a user defined
function
39. Write a Python program to find the highest 2 values in a dictionary. 20-10-23
40. Write a Python program to create a dictionary from a string. 20-10-23
41. Write a program to input your friends’ names and their Phone Numbers and store them in the dictionary as 20-10-23
the key-value pair. Perform the following operations on the dictionary: Display the name and phone
number of all your friends
PRACTICAL 1
Q.1) Write a Python program to convert temperature in degree Celsius to degree Fahrenheit. If
water boils at 100 degree C and freezes as 0 degree C, use the program to find out what is the
boiling point and freezing point of water on the Fahrenheit scale.
Source code
3
OUTPUT
PRACTICAL 2
Q.2) Write a Python program to calculate the amount payable if money has been lent on simple
interest. Principal or money lent = P, Rate of interest = R% per annum and Time = T years.
Then Simple Interest (SI) = (P x R x T)/ 100. Amount payable = Principal + SI. P, R and T are
given as input to the program.
Source code
4
OUTPUT
PRACTICAL 3
Q.3) Write a program to calculate in how many days a work will be completed by three
persons A, B and C together. A, B, C take x days, y days and z days respectively to do the job
alone. The formula to calculate the number of days if they work together is xyz/ (xy + yz + xz)
days where x, y, and z are given as input to the program.
Source code
5
OUTPUT
PRACTICAL 4
Q.4) Write a program to enter two integers and perform all arithmetic operations on them.
Source code
6
OUTPUT
PRACTICAL 5
Q.5) Write a program to swap two numbers using a third variable.
Source code
7
OUTPUT
PRACTICAL 6
Q.6) Write a program to swap two numbers without using a third variable.
Source code
8
OUTPUT
PRACTICAL 7
Q.7) Write a program to repeat the string ‘‘GOOD MORNING” n times. Here ‘n’ is an integer
entered by the user.
SOURCE CODE
9
OUTPUT
PRACTICAL 8
Q.8) Write a program to find average of three numbers.
SOURCE CODE
10
OUTPUT
PRACTICAL 9
Q.9) The volume of a sphere with radius r is 4/3πr3. Write a Python program to find the
volume of spheres with radius 7cm, 12cm, 16cm, respectively.
Source code
11
OUTPUT
PRACTICAL 10
Q.10) Write a program that asks the user to enter their name and age. Print a message
addressed to the user that tells the user the year in which they will turn 100 years old.
Source code
12
OUTPUT
PRACTICAL 11
Q.11) The formula E = mc² states that the equivalent energy (E) can be calculated as the mass
(m) multiplied by the speed of light (c = about 3×10⁸ m/s) squared. Write a program that
accepts the mass of an object and determines its energy.
Source code
13
OUTPUT
PRACTICAL 12
Q.12) Presume that a ladder is put upright against a wall. Let variables length and angle store
the length of the ladder and the angle that it forms with the ground as it leans against the wall.
Write a Python program to compute the height reached by the ladder on the wall for the
following values of length and angle: a) 16 feet and 75 degrees
Source code
14
OUTPUT
PRACTICAL 13
Q.13) Write a program that takes the name and age of the user as input and displays a message
whether the user is eligible to apply for a driving license or not. (The eligible age is 18 years).
Source code
15
OUTPUT
PRACTICAL 14
Q.14) Write a function to print the table of a given number. The number has to be entered by
the user.
Source code
16
OUTPUT
PRACTICAL 15
Q.15) Write a program that prints minimum and maximum of five numbers entered by the user.
Source code
17
OUTPUT
PRACTICAL 16
Q.16) Write a program to check if the year entered by the user is a leap year or not.
Source code
18
OUTPUT
PRACTICAL 17
Q.17) Write a program to generate the sequence: –5, 10, –15, 20, –25…... upto n, where n is an
integer input by the user.
Source code
19
OUTPUT
PRACTICAL 18
Q.18) Write a program to find the sum of 1+ 1/8 + 1/27......1/n3, where n is the number input
by the user
Source code
20
OUTPUT
PRACTICAL 19
Q.19) Write a program to find the sum of digits of an integer number, input by the user.
Source code
21
OUTPUT
PRACTICAL 20
Q.20) Write a function that checks whether an input number is a palindrome or not
Source code
22
OUTPUT
PRACTICAL 21
Q.21) Write a program to print the following patterns
23
Source code
OUTPUT
PRACTICAL 22
Q.22) Write a program to find the grade of a student when grades are allocated as given in the
table below. Percentage of the marks obtained by the student is input to the program.
Source code
24
OUTPUT
PRACTICAL 23
Q.23) Write a program to input line(s) of text from the user until enter is pressed. Count the
total number of characters in the text (including white spaces), total number of alphabets, total
number of digits, total number of special symbols and total number of words in the given text.
(Assume that each word is separated by one space).
Source code
25
OUTPUT
PRACTICAL 24
Q.24) Write a user defined function to convert a string with more than one word into title case
string where string is passed as parameter. (Title case means that the first letter of each word is
capitalised)
Source code
26
OUTPUT
PRACTICAL 25
Q.25) Write a function deleteChar() which takes two parameters one is a string and other is a
character. The function should create a new string after deleting all occurrences of the character
from the string and return the new string.
Source code
27
OUTPUT
PRACTICAL 26
Q.26) Input a string having some digits. Write a function to return the sum of digits present in
this string.
Source code
28
OUTPUT
PRACTICAL 27
Q.27) Write a function that takes a sentence as an input parameter where each word in the
sentence is separated by a space. The function should replace each blank with a hyphen and
then return the modified sentence.
Source code
29
OUTPUT
PRACTICAL 28
Q.28) Write a program to find the number of times an element occurs in the list.
Source code
30
OUTPUT
PRACTICAL 29
Q.29) 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.
Source code
31
OUTPUT
PRACTICAL 30
Q.30) Write a function that returns the largest element of the list passed as parameter.
Source code
32
OUTPUT
PRACTICAL 31
Q.31) Write a function to return the second largest number from a list of numbers.
Source code
33
OUTPUT
PRACTICAL 32
Q.32) Write a program to read a list of n integers and find their median.
Source code
34
OUTPUT
PRACTICAL 33
Q.33) 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.
35
Source code
OUTPUT
PRACTICAL 34
Q.34) 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.
Source code
36
OUTPUT
PRACTICAL 35
Q.35) Write a program to read elements of a list. a) The program should ask for the position of
the element to be deleted from the list. Write a function to delete the element at the desired
position in the list. b) The program should ask for the value of the element to be deleted from
the list. Write a function to delete the element of this value from the list.
37
Source code
OUTPUT
PRACTICAL 36
Q.36) Read a list of n elements. Pass this list to a function which reverses this list in-place
without creating a new list.
Source code
38
OUTPUT
PRACTICAL 37
Q.37) Write a program to read email IDs of n number of students and store them in a tuple. Create
two new tuples, one to store only the usernames from the email IDs and second to store domain
names from the email IDs. Print all three tuples at the end of the program
Source code
39
OUTPUT
PRACTICAL 38
Q.38) Write a program to input names of n students and store them in a tuple. Also, input a name
from the user and find if this student is present in the tuple or not, we can accomplish these by:
writing a user defined function
Source code
40
OUTPUT
PRACTICAL 39
Q.39) Write a Python program to find the highest 2 values in a dictionary.
Source code
41
OUTPUT
PRACTICAL 40
Q.40) Write a Python program to create a dictionary from a string.
Source code
42
OUTPUT
PRACTICAL 41
Q.41) Write a program to input your friends’ names and their Phone Numbers and store them in the
dictionary as the key-value pair. Perform the following operations on the dictionary: Display the
name and phone number of all your friends
Source code
43
OUTPUT
44