You are on page 1of 36

Page 1 of 36

Program 1: Program to enter two numbers and


print the arithmetic operations like +,-,*, /, // and
%.

SOURCE CODE

OUTPUT:
Page 2 of 36

Program 2: Write a program to find whether an


inputted number is perfect or not.

SOURCE CODE

OUTPUT:
Page 3 of 36

Program 3: Write a Program to check if the


entered number is Armstrong or not.

SOURCE CODE

Output:
Page 4 of 36

OR

SOURCE CODE

Output:
Page 5 of 36

Program 4: Write a Program to find factorial of


the entered number.

SOURCE CODE

Output:
Page 6 of 36

Program 5: Write a Program to enter the


number of terms and to print the Fibonacci
Series.

SOURCE CODE

Output:
Page 7 of 36

Program 6: Write a Program to enter the string


and to check if it’s palindrome or not using loop.

SOURCE CODE

Output:
Page 8 of 36

OR

SOURCE CODE

Output:
Page 9 of 36

OR

SOURCE CODE

Output:

Yes
Page 10 of 36

Program 7: Recursively find the factorial of a


natural number.

SOURCE CODE

Output:
Page 11 of 36

Program 8: Read a file line by line and print it.

Assume we have the following file, located in the same


folder as Python:

SOURCE CODE

Output:
Page 12 of 36

Program 9: Remove all the lines that contain the


character “a” in a file and write it into another
file.

Assume we have the following file, located in the same


folder as Python:

SOURCE CODE

Output:
Page 13 of 36

Program 10: Read a text file and display the


number of
vowels/consonants/uppercase/lowercase
characters in the file.

Actual text file


Page 14 of 36

SOURCE CODE

Output:
Page 15 of 36

Program 11: Create a binary file with name and


roll no. Search for a given roll number and
display the name, if not found display
appropriate message.

SOURCE CODE
Page 16 of 36

Output:
Page 17 of 36

OR

Output:
Page 18 of 36

Program 12: Write a random number generator


that generates random numbers between 1 and
6(simulates a dice)

SOURCE CODE

Output:
Page 19 of 36

Program 13: Write a python program to


implement a stack using a list data structure.

Stack Concept (SOURCE CODE):

Output:
Page 20 of 36

Queue Concept (SOURCE CODE):

Output:
Page 21 of 36

Program 14: Take a sample of ten phishing e-


mails (or any text file) and find most commonly
occurring word(s)
SOURCE CODE
Page 22 of 36

Output:
Page 23 of 36

Program 15: Read a text file line by line and


display each word separated by a #

SOURCE CODE

Output:
Page 24 of 36

Program 16: Create a student table and insert


data. Implement the following SQL commands
on the student table:

• ALTER table to add new attributes / modify data type /


drop attribute

• UPDATE table to modify data

• ORDER By to display data in ascending / descending order

• DELETE to remove tuple(s)

• GROUP BY and find the min, max, sum, count and average
Page 25 of 36

SOURCE CODE
Page 26 of 36
Page 27 of 36
Page 28 of 36
Page 29 of 36
Page 30 of 36
Page 31 of 36
Page 32 of 36

Program 17: Integrate SQL with Python by


importing the MySQL module

SOURCE CODE
Page 33 of 36

Program 18: Integrate SQL with Python by


importing the py mysql module.

SOURCE CODE
Page 34 of 36

Program 19:Creating a Table


To create a table in MySQL, use the "CREATE TABLE"
statement.
Make sure you define the name of the database when
you create the connection.

SOURCE CODE
Page 35 of 36

Program20: Database table of empl

• Calculate average salary of all employees listed in table


empl.
Source code
mysql> SELECT AVG(sal) "Average"
FROM empl;

Output:
Average
12073.928571
Page 36 of 36

• Count number of records in table empl Solution.

Source code

mysql> SELECT COUNT(*) "Total"


FROM emp);

Output:

Total
14

You might also like