0% found this document useful (0 votes)
1 views32 pages

Python Programs

Uploaded by

harshkaur.636
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)
1 views32 pages

Python Programs

Uploaded by

harshkaur.636
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

#PYTHON PROGRAMS

PROGRAM 1: Write a program to search an


element in a list & display the frequency of elements
present in list.
Source code:

Output:

1 | Page
PROGRAM 2: WAP to search an element in list
& print the location of that element.
Source code:

Output:

2 | Page
PROGRAM 3: WAP to calculate factorial of
entered number.
Source code:

Output:

3 | Page
PROGRAM 4: WAP to pass a string to a function
& count how many vowels are present.
Source code:

Output:

4 | Page
PROGRAM 5: WAP to generate random number
between 1 to 6 to simulate a dice.
Source code:

Output:

5 | Page
PROGRAM 6: WAP to read a text file & display
the number of vowels, consonants, upper case &
lower case characters in a file.

Text file:

6 | Page
Source code:

Output:

7 | Page
PROGRAM 7: Create a binary file with Name
and Roll number. Search for a given Roll number &
display the name. If not found, display appropriate
message.
Source code:

8 | Page
Output:

9 | Page
PROGRAM 8: WAP to create a CSV file by
entering user-id & password.
Source code:

10 | P a g e
Output:

11 | P a g e
PROGRAM 9: WAP to display ASCII code of a
character.
Source code:

Output:

12 | P a g e
PROGRAM 10: WAP to implement 5 python
string operations.

Source code:

Output:

13 | P a g e
PROGRAM 11: WAP to implement Stack
operations.
Source code:

14 | P a g e
Output:

15 | P a g e
PROGRAM 12: WAP to return a dictionary with
elements of a list as keys & frequency of its
occurrences as value.
Source code:

Output:

16 | P a g e
PROGRAM 13: WAP that accepts a string &
calculates the number of uppercase and lowercase
letters.
Source code:

Output:

17 | P a g e
PROGRAM 14: WAP to input two integers and
find their LCM.

Source code:

Output:

18 | P a g e
PROGRAM 15: WAP to calculate simple interest
& amount payable by inputting principal amount and
rate from use for a period of 5 years.
Source code:

Output:

19 | P a g e
#SQL Queries
[Link] a SQL command to create a database named
‘School’. Also write command to create a Student
table with Student id, name & marks as attributes
where Student id is the primary key. Also perform the
following queries:
 Add columns ‘Mobile’ & ‘Sex’.
 Add column ‘Address’.
 Change name of column ‘Sex’ to ‘Gender’.
 Delete a column ‘Address’.

20 | P a g e
 Add columns ‘Mobile’ & ‘Sex’ in the table
Student

 Add column ‘Address’.

21 | P a g e
 Change name of column ‘Sex’ to ‘Gender’.

 Delete a column ‘Address’.

22 | P a g e
2. Create a table named Student. Add columns
Student id, Name, Address, Mobile, DOB & Fee. Also
perform following queries:
 Insert some data into the table Student.
 Show the table Student.
 Show details of students with fee more than
12600.
 Show details of students with fee less than
12600.

23 | P a g e
 Insert data in Student.

 Show table.

24 | P a g e
 Show details of students with fee more than
12600.

 Show details of students with fee less than


12600.

25 | P a g e
3. Create a table ‘student’ with the following fields:
Student id, name & marks. Perform following queries:
 Insert records.
 Find the maximum, minimum and average of
marks.
 Sort in descending order with accordance to
marks.
 Delete the record of the student with student id
as 5.

26 | P a g e
 Insert records

 Find max, min & avg of marks.

27 | P a g e
 Sort in descending order according to marks.

 Delete the record of student with student id


as 5.

28 | P a g e
#Python-SQL Connectivity
[Link] a Python SQL connectivity program to insert
records to Emp table and display the records.

Source code:

Python output:

29 | P a g e
MySQL output:

30 | P a g e
2. Write a python program to search an Employee
using EMPID and display the record if present, if not
then display the appropriate message.
Source code:

Output:
 Python output:

 MySQL output:
31 | P a g e
 Python output:

 MySQL output:

32 | P a g e

You might also like