Computer Science Practical File
Computer Science Practical File
Output:
1 is palindrome
2 is palindrome
3 is palindrome
4 is palindrome
5 is palindrome
6 is palindrome
7 is palindrome
8 is palindrome
9 is palindrome
11 is palindrome
22 is palindrome
33 is palindrome
44 is palindrome
55 is palindrome
66 is palindrome
77 is palindrome
88 is palindrome
99 is palindrome
Output:
P
Py
Pyt
Pyth
Pytho
Python
6.WAP to find the factorial of a number by using
function.
Output:
Enter a number: 5
The factorial of 5 is 120
11.Write a function in python that counts the
number of Me/My words present in a text file
Story.txt. Consider the following content: “My first
book was me and my family. It gave me a chance to be
known to the world.”
Output:
Enter the number of elements you want to add: 4
Enter key: Adm No
Enter values: 3356 3258 3483
Enter key: Name
Enter values: Aarju Mohini Gauri
Enter key:Class
Enter values: 12 12 12
Enter key: Stream
Enter values: PCB PCM PCB
Original dictionary: {‘Adm No’: [‘3356’, ‘3258’, ‘3483’],
‘Name’: [‘Aarju’, ‘Mohini’, ‘Gauri’], ‘Class’: [‘12’, ‘12’,
‘12’], ‘Stream’: [‘PCB’, ‘PCM’, ‘PCB’]}
Copied dictionary: {‘Adm No’: [‘3356’, ‘3258’, ‘3483’],
‘Name’: [‘Aarju’ ‘Mohini’, ‘Gauri’], ‘Class’: [‘12’, ‘12’,
‘12’], ‘Stream’: [‘PCB’ ‘PCM’, ‘PCB’]}
if choice == 1:
print(num1, ‘+’, num2, ‘=’, add(num1, num2))
elif choice == 2:
print(num1, ‘-’, num2, ‘=’, subtract(num1, num2))
elif choice == 3:
print(num1, ‘*’, num2, ‘=’, multiply(num1, num2))
elif choice == 4:
print(num1, ‘/’, num2, ‘=’, divide(num1, num2))
elif choice == 5:
print(‘Exit program’)
break
else:
print(‘Invalid Choice’)
Output:
Select operation.
1.Add
2.Subtract
3.Multiply
4.Divide
5.Exit
Enter your choice: 1
Enter first number: 34
Enter second number: 54
34 + 54 = 88
Select operation.
1.Add
2.Subtract
3.Multiply
4.Divide
5.Exit
Enter your choice: 2
Enter first number: 79
Enter second number: 43
79 – 43 = 36
Select operation.
1.Add
2.Subtract
3.Multiply
4.Divide
5.Exit
Enter your choice: 3
Enter first number: 24
Enter second number: 12
24 * 12 = 288
Select operation.
1.Add
2.Subtract
3.Multiply
4.Divide
5.Exit
Enter your choice: 4
Enter first number: 45
Enter second number: 5
45 / 5 = 9.0
Select operation.
1.Add
2.Subtract
3.Multiply
4.Divide
5.Exit
Enter your choice: 5
Exit program
Output:
Enter upper range: 10
2
3
5
7
8.WAP using a function to accept characters in a
list then find and display vowels present in the list.
Output:
Enter a list of characters: a f e g I m u s
a
e
I
u
9.WAP that takes a string as input and count the
number of uppercase and lowercase letters
present in the string by using function.
Output:
Enter the string: Write a Python Program
Number of upper case letters: 3
Number of lower case letters: 16
10.Write a function in python to create a text file
Story.txt.
Output:
Enter file content: My first book was me and my
family. It gave me
a chance to be known to the world.
File created successfully.
12.Write a function in python to count the number
of lines in a text file Story.txt that are starting
with an alphabet ‘A’. Consider the following
content: “A boy is playing there. There is a playground.
An aeroplane is in the sky. Alphabets and numbers are
allowed in password.”
Output:
Existing records
Player code: 5678
Player name: Dev
Player score:358
Player rank: 4
Append data
Enter player code: 3356
Enter player name: Chah
Enter player score: 423
Enter player rank: 3
Output:
Data Stored in a file
Enter the player code: 5678
Record found
Player name: Dev
Player score: 358
Player rank: 4
Output:
Enter the player code: 5678
File deleted!
17.A binary file Book.dat has structure:
[Bookno, Bookname, Author, Price]
i)Write a user defined function createFile() to
input data for a
record and add to Book.dat.
Output:
Enter book number: 083
Enter book name: Comp. Sc.
Enter book author: Sumita Arora
Enter book price: 675
ii)Write a function countRec() which accepts the
author name as
parameter and count and return the number of
books by the
given author stored in the binary file Book.dat.
Output:
Enter book author: Sumita Arora
Number of books given by Sumita Arora: 2