Xii CSC Practicals-Ii
Xii CSC Practicals-Ii
Xii CSC Practicals-Ii
NO – 4 CSV FILES
14. Result.csv is created to store the results of students in different sports.
The structure of Result.csv is :
[St_Id, St_Name, Game_Name, Result]
Result is result of the game whose value can be either 'Won', 'Lost' or 'Tie'
Write the following user defined functions:
Accept() – to accept a record from the user and add it to the file Result.csv. The column
headings should also be added on top of the csv file.
wonCount() – to count the number of students who have won any event.
import csv
def accept():
f=open('result.csv','a',newline='')
y=1
while y==1:
id=int(input("Enter student ID-"))
name=input("Enter student name-")
g_name=input("Enter game name-")
res=input("Enter the result Won/Lost/Tie-")
data=[id,name,g_name,res]
wr=csv.writer(f)
wr.writerow(["Studentid","SName","GameName","Result"])
wr.writerow(data)
y=int(input("Whether you want to add more students. If yes press 1--"))
f.close()
def wonCount():
with open('result.csv','r') as f:
cnt=0
data=csv.reader(f)
for i in data:
if i[3].lower()=='won':
cnt+=1
print(i)
print("No. of students won any event is",cnt)
accept()
wonCount()
OUTPUT
Enter student ID-2005
Enter student name-SURAJ
Enter game name-CRICKET
Enter the result Won/Lost/Tie-WON
Whether you want to add more students. If yes press 1--1
Enter student ID-2158
Enter student name-YASER
Enter game name-FOOTBALL
Enter the result Won/Lost/Tie-LOST
Whether you want to add more students. If yes press 1--2
['2005', 'SURAJ', 'CRICKET', 'WON']
No. of students won any event is 1
EX.NO – 5 STACK
15. A list, NList contains following record as list elements:
[City, Country, distance from Delhi]
Each of these records are nested together to form a nested list. Write the following user defined
functions in Python to perform the specified operations on the stack named travel.
Push_element(NList): It takes the nested list as an argument and pushes a list
object containing name of the city and country, which are not in India and distance is less
than 3500 km from Delhi.
Pop_element(): It pops the objects from the stack and displays them. Also, the function
should display “Stack Empty” when there are no elements in the stack.
NList=[["NewYork","U.S.A",11734],["Dubai","UAE",2194],
["London","England",6693],["Columbo","Srilanka",3405]]
travel=[]
def Push_element(NList):
for i in NList:
if i[1]!="India" and i[2]<3500:
travel.append([i[0],i[1]])
def Pop_element():
while len(travel):
print(travel.pop())
else:
print("Stack nempty")
Push_element(NList)
Pop_element()
OUTPUT
['Columbo', 'Srilanka']
['Dubai', 'UAE']
Stack nempty
16. Write a function in Python, Push (Vehicle) where, Vehicle is a dictionary containing details of
vehicles - {Car_Name: Maker}.
The function should push the name of car manufactured by "TATA' (including all the possible
cases like Tata, TaTa, etc.) to the stack.
17. Write a Python program that displays all records through Python Program. User Name as
‘Root’, Password as ‘coresql’, database as ‘ mysql’, Table name as ‘employee’]
OUTPUT
18 Write a program to increase the salary of all employees by 1000, through Python program.
[User Name as ‘Root’, Password as ‘coresql’, database as ‘ mysql’, Table name as
‘employee’]
import mysql.connector as sqltor
mycon=sqltor.connect(host="localhost",user="root",passwd="coresql",database="mysql")
mycur=mycon.cursor()
mycur.execute("update employee set salary=salary+1000")
print("Changes done successfully")
mycon.commit()
mycon.close()
OUTPUT
Changes done successfully
19 Write a program to add a new record into the table, through Python program. [User Name
as ‘Root’, Password as ‘coresql’, database as ‘ mysql’, Table name as ‘employee’]. The
new record values has to be accepted from the user
OUTPUT
Data added successfully
EX. NO.: 7 DDL COMMANDS
a) Write MySQL statement to create a database named FOOD.
b) Write MySQL statement to create a table named Nutrients based on the following
specification.
Column name Data type Constraints
P_ID Char(3) Primary key
Name Char(12)
Desig Char(15)
Salary Integer(6)
Allowance Integer(5)
c) Write MySQL statement to add a new column dept of suitable data type?
d) Write MySQL statement to display the attributes, its data type and constraints.
e) Write MySQL statement to remove the table from the database.
Ans: a) create database food;
b) create table Personal(P_ID char(3) primary key, Name char(12), Desig char
(15),Salary integer(6), Allowance integer(5));
d) desc personal;
d)
Based on the given table, write SQL queries for the following:
a) To insert the details of ‘Ravina’ into the table.
b) Display the details of clerks.
c) Display all the different designations.
d) Display ID, name and salary of personals whose name contains ‘hi’ anywhere
and salary in the range 40000 to 90000.
e) Display the names of personals whose are getting salary.
f) Display the details of all supervisors and managers.
g) Display Name and Total Salary (sum of Salary and Allowance) of all
personals. The column heading ‘Total Salary’ should also be displayed.
h) To change the salary of clerk whose is getting null with 10000.
i) Increase the salary by 5% of all personals.
j) Delete the record of Supervisors who have salary greater than 25000.
Ans: a) insert into Personal values('P05','Ravina','Supervisor',null,2100);
d) select P_ID, name, salary from personal where name like '%hi%' and salary
between 40000 and 90000;
b)
c)
d)
e)
f)
g)
c)
d)
e)
f)
g)
Table: BRAND
b)
c)
d)
e)