Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

Python file

Pyhton code 20 for class 12

Uploaded by

rajannoida2006
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Python file

Pyhton code 20 for class 12

Uploaded by

rajannoida2006
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

S.No Codes Page No.

1 Write a Python program to remove the nth index character from a


nonempty string.

2 Write a program to reverse a string.

3 Write a Python program to perform the following operations on a


string: a) Prompt the user to input a string. b) Extract all digits from the
string, if present. c) Calculate and display the sum of the digits. i)
Display the digits. ii) Display the original string. iii) Display the sum of
the digits. d) If no digits are present, display the original string along
with the message "No Digits are present."

4 Write a Python program to compute the total salary of the employee


and also calculate the size of the binary file named "empfile.dat", the
file consists of the following fields: employee number, employee
name, basic salary, allowance. (Hint: Total salary = basic + allowance)

5 Write a Python program to display all the records in a file along with
line/record numbers.

6 Write a menu-driven program to perform read and write operations


using a text file called "student.txt", containing student roll-no, name,
and address using two separate functions as given below:

7 A binary file "Book.dat" has a structure [Book No, Book Name, Author,
Price]. Write a user-defined function Createfile() to input data for a
record and add it to 'Book.dat'. Also, write a function Countrec(Author)
in Python which accepts the Author name as a parameter and counts
and returns the number of books by the given Author stored in the
binary file "Book.dat".

8 Write a Python program to implement a stock that contains two types


of information: a book number and its name. Just implement PUSH
and DISPLAY operations.

9 Write a program to save student information like admission number,


roll number, name, and marks in a dictionary, and display the
information based on the admission number.
10 Write a Python program to create a text file and print the lines starting
with 'T' or 'p'.

11 Write a menu-based program to add, delete, and display the record of


a hostel using a list as a stack data structure in Python. The record of a
hostel contains the fields: Hostel number, Total students, and Total
rooms.

12 Write a function LShift(arr, n) in Python which accepts a list arr of


numbers and a numeric value n by which all elements of the list are
shifted to the left.

13 Write a function countH() in Python to display the number of lines


starting with 'H' in the file "Para.txt".

14 Write a menu-driven program implementing user-defined functions to


perform different operations on a CSV file "student" such as: a) Write a
single record to the CSV. b) Write all records in one go to the CSV. c)
Display the contents of the CSV file.

15 Write a function countmy() in Python to read the text file "data.txt"


and count the number of times 'my' occurs in the file.

16 What are the benefits of using the "with open()" method over "open()"
while opening a file? Write a Python program that defines and calls the
following user-defined functions: i) Add_item to accept and add data
of stationary items to a CSV file "stationery.csv". The record consists of
a list with field elements as Item_Id, Item_name, and Item_price. ii)
Count() to count the total number of stationary items in the CSV file.

17 SS Public School is managing student data in the 'student' table in the


'school' database. Write Python code that connects to the database
'school' and retrieves all records, displaying the total number of
students.

18 Write code to connect to a MySQL database 'school' and retrieve all


records from the 'student' table where grade is 'A'.
19 Write a Python connectivity program to retrieve data, one record at a
time, from the 'EMP' table for employees with ID < 10.

20 Consider a database 'company' that has a table 'emp' that stores


details of many employees. Write a MySQL Python connectivity
program to retrieve data one record at a time for employees with
ID < 10.

You might also like