0% found this document useful (0 votes)
32 views4 pages

Updated Practical File Sarvesh Singh

Uploaded by

sarvesh27singh
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)
32 views4 pages

Updated Practical File Sarvesh Singh

Uploaded by

sarvesh27singh
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
You are on page 1/ 4

Python Practical File: Updated Index

Index

1. Longest word in a string passed to a function ........... Page 2


2. Count multiples of 5 in a list passed to a function .... Page 3
3. Count occurrences of an element in a tuple ............. Page 4
4. Count lines starting with 'A' in a text file ........... Page 5
5. Count and display word lengths in a text file .......... Page 6
6. Add a student record to a binary file .................. Page 7
7. Display all student records from a binary file ......... Page 8
8. Create and display contents of a CSV file .............. Page 9
9. Display words in a text file separated by `#` .......... Page 10
10. Search for a number in a list ......................... Page 11
11. Analyze a text file for alphabets, digits, etc. ....... Page 12
12(a). Pass a string to a function and display it ......... Page 13
12(b). Pass a dictionary to a function and display it ..... Page 14
13. Calculate the sum of digits of a number ............... Page 15
14. Generate random numbers (simulate a dice) ............. Page 16
15. Implement a stack using a list ....................... Page 17
Python Practical File

Name: Sarvesh Singh

Class: 12

School: Kidde's Conner Hr. Secondary School

Session: 2024-2025

Index
1. Longest word in a string passed to a function.

2. Count multiples of 5 in a list passed to a function.

3. Count occurrences of an element in a tuple.

4. Count lines starting with 'A' in a text file.

5. Count and display word lengths in a text file.

6. Add a student record to a binary file.

7. Display all student records from a binary file.

8. Create and display contents of a CSV file.

9. Display words in a text file separated by `#`.

10. Search for a number in a list.

11. Analyze a text file for alphabets, digits, etc.

12(a). Pass a string to a function and display it.

12(b). Pass a dictionary to a function and display it.

13. Calculate the sum of digits of a number.

14. Generate random numbers (simulate a dice).

15. Implement a stack using a list.


1. Longest word in a string passed to a function

Code:

def longest_word(s):

words = s.split()

return max(words, key=len)

# Test

string = "The quick brown fox"

print("Longest word:", longest_word(string))

Output:

Longest word: quick


2. Count multiples of 5 in a list passed to a function

Code:

def count_multiples_of_5(lst):

return len([x for x in lst if x % 5 == 0])

# Test

lst = [10, 23, 45, 66, 90]

print("Count of multiples of 5:", count_multiples_of_5(lst))

Output:

Count of multiples of 5: 3

You might also like