KEMBAR78
Python Codes Pt2. X | PDF | Comma Separated Values | Text File
0% found this document useful (0 votes)
10 views20 pages

Python Codes Pt2. X

The document outlines a series of programming tasks that involve user-defined functions (UDFs) for various operations, including arithmetic calculations, file handling, and data processing. Each task is accompanied by a brief description, code placeholders, and expected outputs. The tasks cover a range of topics from basic programming concepts to handling binary and CSV files.

Uploaded by

Yukti Sharma
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)
10 views20 pages

Python Codes Pt2. X

The document outlines a series of programming tasks that involve user-defined functions (UDFs) for various operations, including arithmetic calculations, file handling, and data processing. Each task is accompanied by a brief description, code placeholders, and expected outputs. The tasks cover a range of topics from basic programming concepts to handling binary and CSV files.

Uploaded by

Yukti Sharma
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/ 20

1.

Write a program to input to numbers and display their sum,


product and difference using 3 different User defined functions.

CODE-

OUTPUT-
2. Write a program to calculate factorial of a number NUM through a
UDF fact(NUM).

CODE-

OUTPUT-
3. Write a program to Input an integer N and find whether it is prime or
not through a UDF prime(N).

OUTPUT-

CODE-
4. Write a program to read a text file input.txt and display each word
separated by a #.

TEXT FILE-

CODE-

OUTPUT-
5. Write a program to read a text file story.txt and display the number of
vowels, consonants, uppercase lowercase characters in the file.

TEXT FILE-

CODE-

OUTPUT-
6. Write a program to read a text file paragraph.txt. Write the lines starting
with letter T from paragraph.txt to another file LINES.txt.

CODE-

OUTPUT-
7. Write a program to input the details of an employee i.e, empID, Name
and Salary and write them inside a file ‘emp.txt’.

CODE-

OUTPUT-
8. Write a menu based program to implement a stack of integers using
user defined push(), pop() and display() functions.
CODE-

OUTPUT-
9. Write a program to Create a binary file Student.dat. The program should
input rollno, name and marks of the students in five subjects and then
write dictionary objects to the file as shown below {“ROLLNO”: 1, “NAME”:
“Rehaan”, “MARKS”: [90, 98, 100, 100, 100]}.

CODE-

OUTPUT-
10. Write a program to read the file Student.dat created in QUESTION 9 and
display the Rollno and the Name of the topper.

CODE-

OUTPUT-
11. Consider the binary file Student.dat created in the pervious question.
Write a user defined function as follows: SearchStudent(): This function
will input the rollno of the student. It will display his total marks if found.
If a Student is not found, display an appropriate message.

CODE-

OUTPUT-
12. Write a program to create a binary file Employee.dat using a function
CREATEBIN(). The function should input the EmployeeID, EmployeeName
and Salary and then write the LIST object into the file in the given format.
[“E1234”, “Reyansh Gupta”, 90000 ]

CODE-

OUTPUT-
13. Consider the Employee.dat file created in the question. Write User
defined function to: 1) Readbinary(): Read and display the contents of the
file. Also display the number of employees 2) SearchBinary(): To input an
employee ID from the user and search whether the employee is present in
file or not. If found, Display his details, else display “Emp not Found”.
CODE-
OUTPUT-
14. Consider the File Employee.dat created above, Write a user defined
function DisplayEMP() which displays the details of the employee whose
salary is above one lakh.

CODE-

OUTPUT-
15. Consider the File Employee.dat created above, Write a user defined
function UPDATEEMP() which inputs an EmployeeID and updates his
salary if found.

CODE-

OUTPUT-
16. Write a program to implement a CSV File called BOOKS.csv through the
following functions: a) Add_Records(): This function inputs the details of
the Book, i.e BOOKNAME, PRICE and AUTHOR and adds the records to the
file BOOKS.csv. (Also adds header row at the top of the csv file) b)
Read_Records(): This function reads the file BOOKS.csv and displays the
details of all the books.

CODE-
OUTPUT-
17. Write a program to read the csv file BOOKS.csv and display the name
of the books which cost above 500. Also display the number of such
books.

CODE-

OUTPUT-

You might also like