0% found this document useful (0 votes)
6 views50 pages

Python and SQL Programming Exercises

The document contains a series of programming exercises and SQL queries designed to enhance skills in Python and MySQL. It includes tasks such as converting temperature, performing arithmetic operations, creating functions for geometric calculations, and manipulating text and binary files. Additionally, it outlines SQL commands for creating and managing student and employee databases, as well as various operations like updating, deleting, and querying data.

Uploaded by

manavdimri17
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)
6 views50 pages

Python and SQL Programming Exercises

The document contains a series of programming exercises and SQL queries designed to enhance skills in Python and MySQL. It includes tasks such as converting temperature, performing arithmetic operations, creating functions for geometric calculations, and manipulating text and binary files. Additionally, it outlines SQL commands for creating and managing student and employee databases, as well as various operations like updating, deleting, and querying data.

Uploaded by

manavdimri17
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

Index

Python
Programs

1. Write a program to obtain temperature in


Celsius and Covert it into Fahrenheit.
2. Write a program to enter two integers and
perform all arithmetic operations on them.
3. Create Functions in Python to calculate Area
and Perimeter of Circle. Write a Python program
to ask user to input their choice 1 or 2. If choice is
1 calculate Area of Circle, if choice is 2 calculate
Perimeter of Circle otherwise show an error
message.
4. Write a functions in Python to multiply two
integer numbers without using the * operator,
using repeated addition.
5. Write program in python to print the given
opposite flyod triangle. (opposite right angle
triangle)
6. Create a function to check the given string is
palindrome. If Palindrome then return True
otherwise return False.
7. Create a Function to Guess_Numbers(), which
ask a number between 1 to 6 form user. Generate
a random number between 1 to 6 through
random module and check the User Guess is
matched or not. Display appropriate message.
8. Create functions Wrtie_Text() and Read_Text().
Write_Text() to write the contents in the text file
“[Link]” line by line. Read_Text() read the text
file “[Link]” and display each word separated
by a ‘@’.
9. Create a function Count_Characters(filename),
which receive filename as argument.
Count_Character(filename) function will read text
file “[Link]” and display the number of vowels,
consonants, uppercase, lowercase, characters in
the file.
10. Create a function Copy_File(target_filename),
which receive filename as argument.
Copy_File(target_filename) function read a text
file “[Link]”, copy those lines only to
target_filename, which are not started with either
‘T’ or ‘A’.
11. Create a binary file “[Link]” with name,
roll number, and marks. Write a function
Search(rollnumber) for a given roll number and
display the name, if not found display appropriate
message.
12. Create a binary file “[Link]” with emp
id,

name and salary. Write a function

Update_Sal(empid), receive an employee id and


update the salary. Write a function
Display(filename), display the all updated records.
13. Create a CSV file by entering user_id and
password, read and search the password for given
user_id.
14. Crate a CSV file “[Link]” by entering roll,
name and marks. Write a function
Grace_5Marks(), which read the csv file and
increase the marks by 5 of students which scored
less than 33. Write a function Display() to display
all records from CSV file.
15. Write a Python program to implement a stack
using list.
My SQL
Queries
1. Create a student table (ADMNO, CLASS-SEC,
NAME, SCORE) and insert data. Implement the
following SQL commands on the student table:

~ ALTER table to add new attributes (SEX


CHAR(1) / modify data type CHAR to VARCHAR/
drop attribute SEX
~UPDATE table to modify data- Increase the
marks of all students by 10 who scored less than
20.
~ ORDER BY to display data in ascending /
descending order by (i) NAME wise (ii) SCORE wise
~ DELETE to remove tuple(s) having SCORE less
than 10.

~ GROUP BY and find the min, max, sum, count


and average
2. Create a EMPLOYEE table (EID, NAME, SALARY,
DEPT) and insert data. Implement the following
SQL commands on the student table:

ALTER table to add new attributes – HRA INT(5) /


modify data type of HRA to decimal / drop
attribute HRA
~UPDATE table to modify data – increase the
salary by 10%

~ORDER BY to display data in ascending /


descending order (i) SALARY wise (ii) EID wise
~DELETE to remove tuple(s) – employee having
emp id 101
~GROUP BY and find the min, max, sum, count
and average.
3. Create a Database LIBRARY. Create a table
BOOKs (book_id (PK), book_name, author_name,
publishers, price, type, qty) and Insert records
Create a table ISSUED(issue_id, book_id (FK),
quantity_issued ) and Insert records.
~To show Book name, Author name and Price of
books of First Publ. publishers.

~To list the names from books of Text type.


~To display the names and price from books in
ascending order.

~To increase the price of all books of EPB


publishers by 50.
~To display the Book_Id, Book_Name. and
Quantity_Issued for all books which have been
issued.

~To display the unique name of all Publishers.


~To display the Maximum and Average Price of
Books Publisher wise.

~SELECT COUNT(*) FROM BOOKS

~SELECT MAX(PRICE) FROM BOOKS WHERE


QUANTITY >= 15;
~ SELECT BOOK_NAME, AUTHOR_NAME FROM
BOOKS WHERE PUBLISHERS = “EPB”;

~SELECT COUNT(DISTINCT PUBLISHERS) FROM


BOOKS WHERE PRICE >= 400;

4. Create a Database COMPANY. Create a table


JOB (JOBID (PK), JOBTITLE, SALARY) and Insert
Records. Create a table Employee (EID (PK),
NAME, SALES, JOBID (FK)) and Insert Records.
~To display employee ids, names of employees,
job ids, with corresponding job titles.

~To display names of employees, sales and


corresponding job titles who have achieved sales
more than 130000.
~To display names and corresponding job titles of
those employees who have ‘SINGH’ (anywhere) in
their names.

~Display the name of employee having maximum


salary.
~Write the SQL command to change the JobId to
104 of the Employee with ID as E4 in the table
EMPLOYEE.
5. Create a Table CLUB (CoachId, CoachName,
Age, Sports, DateofApp, Pay, Sex) and Insert
Records.

~To display the list of coach who is playing


KARATE.
~To display the records having Pay between 500
to 1000.

~To display the names of coach whose name


starts with ‘A’.
~To display the total salary paid to Coach Gender
wise.

~To display all records alphabetically on name.


~SELECT COUNT(DISTINCT SPORTS) FROM CLUB;

~SELECT MIN(AGE) FROM CLUB WHERE SEX = ‘M’;


~SELECT AVG(AGE) FROM CLUB GROUP BY SEX;

~SLEECT SUM(PAY) FROM CLUB WHERE


DATEOFAPP > ’31-03-1998’
Connectivi
ty

programs
1. Write a Python Program to create a Database
named “School”. Display the List of Databases
available in MySQL.
2. Write a Python program to Create a Table name
“Student” under database “School” contained
RollNo, Name, UT1, and UT2 score. Note: UT1 and
UT2 out of 40 only.
3. Write a Python Program to Insert Records in
“Student” table. Display all records. Note: UT1
and UT2 out of 40 only.
4. Write a Python program to increase the marks
of UT1 by 10 of those students having UT1 marks
less than 20. Also display a message how many
records are updated.
5. Write a Python programs to Display Records
form table “Student” with their Total Marks and
Percentage.
Thank
You

Sign of internal:________________

Sign of external:________________

You might also like