pytoh
pytoh
3
1. READ A TEXT FILE BY LINE AND DISPLAY EACH WORD SEPARATED BY A #.
4
2. READ A TEXT FILE AND DISPLAY THE NUMBER OF VOWELS / CONSONANTS / UPPERCASE / LOWERCASE
CHARACTERS IN A FILE.
5
3. READ ALL THE LINES THAT CONTAIN THE CHARACTER ‘A’ IN A FILE AND WRITE IT TO ANOTHER FILE.
6
4. CREATE A BINARY FILE WITH NAME AND ROLL NUMBER. SEARCH FOR A GIVEN ROLL NUMBER AND DISPLAY THE
NAME, IF NOT FIND DISPLAY AN APPROPRIATE MESSAGE.
7
8
5. CREATE A BINARY FILE WITH ROLL NUMBER, NAME AND MARKS. INPUT A ROLL NUMBER AND UPDATE THE MARKS.
9
10
6. WRITE A RANDOM NUMBER GENERATOR THAT GENERATES RANDOM NUMBERS BETWEEN 1 AND 6 (SIMULATES A DICE).
11
7. CREATE A CSV FILE BY ENTERING USER-ID AND PASSWORD, READ AND SEARCH THE PASSWORD FOR GIVEN ID.
12
8. WRITE A FUNCTION COUNTMY() IN PYTHON TO READ THE TEXT FILE “DATA.TXT” AND COUNT THE NUMBER OF TIMES
“MY” OCCURS IN THE FILE.
13
9. WRITE A FUNCTION DISPLAYWORDS() IN PYTHON TO READ LINES FROM A TEXT FILE POEM.TXT AND DISPLAY THOSE
WORDS WHICH ARE LESS THAN 4 CHARACTERS.
14
10. WRITE A MENU DRIVEN PROGRAM TO INPUT A NUMBER AND DISPLAY
IF IT IS A PALINDROME OR NOT
IF IT IS AN ARMSTRING NUMBER
IF IT IS A PERFECT NUMBER
IF IT IS PRIME NUMBER
15
16
11. WRITE A PROGRAM TO INPUT A STRING AND PRINT IF IT IS PALINDROME.
17
12. WRITE A PROGRAM TO STORE STUDENT NAMES AND THEIR PERCENTAGE IN A DICTIONARY AND DELETE A PARTICULAR
STUDENT NAME FROM THE DICTIONARY AND ALSO DISPLAY THE DICTIONARY AFTER DELETION.
18
19
There are following steps to connect a python application to ourdatabase.
Pass the database details like hostname, username and the databasepassword in the
method call. The method returns the connection object.
EXAMPLE:-
OUTPUT:
20
The cursor object can be defined as an abstraction specified in the Python DB-
API2.0. It facilitates us to have multiple separate workingenvironments through the
same connection to the database . We
can create the cursor object by calling the ‘cursor’ function of theconnection object.
OUTPUT:
21
PROGRAM: SHOWING DATABASE
OUTPUT:
OUTPUT:
22
PROGRAM: TO DISPLAY THE TABLES
OUTPUT:
OUTPUT:
23
OUTPUT:
Fetchone( ) : It fetches one row from the result table set in theform of
tuple or a list. A result set is an object that is returned when a cursor object is
used to query a table. This function shall return onerecord from the result set,
i.e. first time it will return the first record, next time it will return the second
record and so on. If no more record is left in the table, it will return None.
fetchall( ) : It fetches all the rows in a result set and returns a list of
tuples. If some rows have already been extracted from the result set, then it
retrieves the remaining rows from the result set. Ifno more rows are available,
it returns an empty set.
24
1. USING FETCHALL
OUTPUT:
2. USING ROWCOUNT
OUTPUT:
3. USING FETCHONE
OUTPUT:
25
4. USING FETCHMANY
OUTPUT:
OUTPUT:
26
STRUCTURED
QUERY
LANGUAGE
27
Sql(Structured Query Language) is a standard language for accessing and manipulating
database. SQL commands are used to create transform and retrieve information from
Relational Database Management System and also to create interface between user
and database. By , using SQL commands, one can search any data in the database and
perform other functions like create tables, add records,modify data, remove rows, drop
table, etc.
28
SQL provides different type of statements or commands fordifferent
purposes. The statements are classified into four categories :
The DDL part of SQL permits database tables to be created ordeleted. It contains
the necessary statements for creating, manipulating, altering and deleting
tables.
Create a database School and create a table Student. Insert data with10 records.
30
STEP 4: Inserting the records in table ‘Student’.
31
WRITE THE COMMANDS TO THE FOLLOWING:
32
4. Display data in alphabetical order of Name.
33
7. Display max, min, sum, count and average marks from the table
Student.
8. Display Rollno, Name and Marks from the Student table who
got the marks between 80 and 100.
34
` 10. Give output for the following code:
36
Step 9: Insert into table 2
2. To display the cost for all the books published for FIRST PUBL.
37
3. To depreciate the price of all books of EPB by 5%.
38