0% found this document useful (0 votes)
7 views2 pages

CS

Uploaded by

sahaana.23.k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

CS

Uploaded by

sahaana.23.k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Write a python program with the following user defined functions to perform the given tasks:

WRITE(): To input a sentence from the user and store it in a file “sample.txt”

READ( ): To read the text file “sample.txt” and print the words which have more than 4
characters in it.

2. Write a python program with the following user defined function to perform the given tasks:
WRITE():To input a sentence from the user and store it in a file “sample.txt”
READ():To Read a text file “sample.txt” and display the number of vowels/ consonants/
uppercase/ lowercase characters present in it.
3. Write a program in python that defines and calls the following functions.
WRITE ( ): To input and store some records into a binary file named “EMPLOYEE.dat” in the
structure [EMPID, EMPNAME, SALARY]
READ ( ): To read and display all records with total number of records stored in the file
4. Write a program in python that defines and calls the following functions.
WRITE ( ): To input and store some records into a csv file named “product.csv” in the
structure[PID,PNAME, PRICE]
READ ( ): To read and display all records whose price is more than 15000
5. You have a stack named StudentStack that contains records of students. Each student record is
represented as a list containing student_name, student_id, and enrollment_year. Write the
following user-defined functions in Python to perform the specified operations on the stack
StudentStack:
push_student(StudentStack, new_student): This function takes the stack StudentStack and a
new student record new_student as arguments and pushes the new student record onto the
stack.
pop_student(StudentStack): This function pops the topmost student record from the stack and
returns it. If the stack is already empty, the function should display "Underflow".
peek(StudentStack): This function displays the topmost element of the stack without deleting it.
If the stack is empty, the function should display 'None'.
6. Write a python program with the following functions.
push_words(word_list) which accepts a list of strings in a parameter word_list and pushes all
those strings that contain more than Four characters into a stack named WordStack.
pop_word() to pop the topmost word from the stack and return it. If the stack is already empty,
the function should display "Stack is empty".
peek_word() to display the topmost element of the stack without deleting it. If the stack is
empty, the function should display 'None'.
7. A binary file “Mobile.dat” has structure [Model, Company, Price].
Write a user defined function in Python to input data for a mobile and add it to a binary file
“Mobile.dat”
Write a function in Python which accepts the company name which counts and returns the
number of mobiles by the given company stored in the binary file “Mobile.dat
A CSV file "Education.csv" contains data from a survey about education levels in different
countries. Each record in the file contains the following data: • country_name (string): Name of
the country • literacy_rate (float): Literacy Rate (percentage of literate adults) • population
(integer): Population (total number of adults) • sample_size (integer): Sample Size (number of
participants in the survey) For example, a sample record of the file may be: [‘CountryX’, 95.5,
20000000, 10000] Write a python program with the following functions to perform the specified
operations on this file: (I) Write a function named add_education_data() to input data for a
country (using variables country_name, literacy_rate, population, and sample_size) and append
it to the CSV file. (II) Write a function named display_high_literacy_records() to read all the data
from the file and display all those records for which the literacy_rate is greater than 90%.

You might also like