Aditya Kumar Shukla
Aditya Kumar Shukla
Shukla
guidance, monitoring and constant
encouragement throughout the course of this
learning.
VISHAL YADAV XII-F
INDEX
S. PROGRAM T. SIGN
No
Q1) Write a python code for a
function(t,n), which repositions
all the elements of array by
shifting each of them to next
position and shifting element to
last position
Q2) write a function SWAP2BEST
(ARR, Size) in python to modify
the content of the list in such a
way that the elements , which
are multiples of 10 swap with
the value present in the very
next position in the list.
def Convert(T,N):
t=T[0]
for i in range(N-1):
T[i]=T[i+1]
T[N-1]=t
print("after conversion",T)
d=[34,38,43,51]
print("Original List",d)
r=len(d)
Convert(d,r)
#OUTPUT:
Original List [34, 38, 43, 51]
after conversion [38, 43, 51, 34]
def SWAP2BEST(A,size):
i=0
while(i,size):
if(A[i]%10==0):
A[i],A[i+1]=A[i+1],A[i]
i=i+2
else:
i=i+1
return(A)
d=[90,56,45,20,34,54]
print("actual list",d)
r=len(d)
print("after swapping",SWAP2BEST(d,r))
#OUTPUT:
Actual list[90,56,45,20,34,54]
After swapping[56,90,45,34,20,54]
#OUTPUT:
1
def Economic():
f1=open("items.dat","ab")
while true:
try:
g=pickle.load(f1)
if(g['cost']<250):
print(g)
except:
break
Economic()
#OUTPUT:
Enter gift name flowers
Enter id 2
Enter cost 500
{‘giftname’ :’ flowers’,’id’:2,’cost’:500.0}
s=[]
def push():
a=int(input("enter ISBN no"))
t=input("enter title")
I=[a,t]
s.append(I)
def disp(s):
if(s==[]):
print("list is empty")
else:
top=len(s)-1
print(s[top],"---top")
for i in range(top-1,-1,-1):
print(s[i])
push()
disp(s)
#OUTPUT:
Enter ISBN no 2
Enter title Encyclopedia
[2,’Encyclopedia’] ---top
def POP(Arr):
if (len(st)>0):
r=st.pop()
return r
else:
print("stack empty")
#OUTPUT:
Blank
def ispalindrome(x):
k=str(x)
I=k[::-1]
if k==I:
print("it is a palindrome")
else:
print("not a palindrome")
x=input("enter next string")
ispalindrome(x)
#OUTPUT:
it is a palindrome
enter next stringswsss
not a palindrome
enter next stringqwer
not a palindrome
#Program 9: WAP to remove all odd numbers from the
given list.
def removeodd(x):
y=[]
for i in x:
if i%2!=0:
k=x.pop(x.index(i))
y.append(k)
else:
pass
print(x)
#OUTPUT:
Remove odd([10,45,88,98,88,100])
[45,98,100]
def pushin():
a=int(input("enter x"))
b=int(input("enter y"))
I=[a,b]
st.append(I)
#OUTPUT:
Pushin()
Enter x1
Enter y2
Stk
[[1,2]]
mycon=con.connect(host="127.0.0.1",user="root",passwd="5971",database="
my school")
#connection check
if mycon.is_connected():
print("connectiion successful")
else:
print("not successful")
#OUTPUT:
Connection successful
file=open('helloworld.txt','r')
line1=file.readline()
a=len(line1)
for i in file:
line=file.readline()
x=len(line)
if x>a:
print(line)
file.close()
#OUTPUT:
This line is the longest line
#Program 15: create a csv file with roll no, name, marks
of students.
import csv
f=open("Student.csv","w",newline='')
s_writer=csv.writer(f,defaulter=';')
s_writer.writerow(['roll no','name','marks'])
rec=[]
while True:
r=int(input("enter roll no:"))
n=int(input("enter marks:"))
lst=[r,n,m]
rec.append(lst)
ch=input("do you want to enter more records?(y/n)")
if ch=='n':
break
for i in rec:
s_writer.writerow(i)
f.close()
#OUTPUT:
Roll no;name;marks
1;arnav;99
2;amit;97
#OUTPUT:
Enter first number: 7
Enter second number: 21
The HCF of 7 and 21 is 7
import mysql.connector
mydb=mysql.connector.connect(host='localhost',user='root',passwd='passwor
d',database='arnavai')
cursor.execute("select *from table1")
records=cursor.fetchone()
for i in records:
print(i)
#OUTPUT:
Arnav Sharan
3
A
Mysql> use arnavai;
Database changed
Mysql>select* from table1;
#Program18: ROWCOUNT
import mysql.connector
mydb=mysql.connector.connect(host='localhost',user='root',passwd='passwor
d',database='arnavai')
cursor=mydb.cursor()
cursor.execute(“UPDATE table1 set Roll=05 where Section=’A’ ”)
mydb.commit(0
print(cursor.rowcount,”Records updated”)
#OUTPUT:
3 Records updated
d=[14,67,32,12]
n=len(d)
for i in range(n):
for j in range(n-i-1):
if(d[j]>d[j+1]):
d[j],d[j+1]=d[j+1],d[j]
print(d)
#OUTPUT:
[12,14,32,67]
OUTPUT:1 2 3 4 5 6 7 8
4.pickle.dump(ID, fin)
5.fin.close()
6.fout = open("Emp.pkl",'rb')
7.ID = pickle.load(fout)
8.print(ID[5])
Ans:-
OUTPUT
Dunzo
MY SQL
[QUESTIONS]
#OUTPUT QUESTIONS
Ans:-
(i) TEACHER_NAME DOJ
AMIT 2007-09-05
ANKIT 2007-09-20
BALBIR 2010-02-15
JASBIR 2011-01-20
KULBIR 2008-07-11
(ii)
TEACHER_CODE TEACHER_NAME DOJ
Table : TRANSACT
TRNO ANO AMOUNT TYPE DOT
Ans:-
COUNT(*) SUM(AMOUNT)
2 5000
#COMMANDS QUESTION
Answer
1.
SELECT *
FROM Teacher
WHERE Department = 'History' ;
Output
+----+----------+-----+------------+--------+-----+------------+
| No | Name | Age | Department | Salary | Sex | Dateofjoin |
+----+----------+-----+------------+--------+-----+------------+
| 2 | Sharmila | 31 | History | 20000 | F | 1998-03-24 |
| 4 | Sangeeta | 35 | History | 40000 | F | 1999-07-01 |
| 6 | Shyam | 50 | History | 30000 | M | 1998-06-27 |
+----+----------+-----+------------+--------+-----+------------+
2.
SELECT Name
FROM Teacher
WHERE Sex = 'F' and Department = 'Hindi' ;
Explanation
Output
+----------+------------+
| Name | Dateofjoin |
+----------+------------+
| Sandeep | 1996-12-12 |
| Jugal | 1997-01-10 |
| Shiv Om | 1997-02-25 |
| Shalakha | 1997-07-31 |
| Rakesh | 1997-09-05 |
| Sharmila | 1998-03-24 |
| Shyam | 1998-06-27 |
| Sangeeta | 1999-07-01 |
+----------+------------+
Answer
1.
SELECT Title
FROM MOV
WHERE Price > 20
ORDER BY Price ;
Output
+--------------------+
| Title |
+--------------------+
| Splash |
| Tootsie |
| Cocoon |
| Gone with the Wind |
| Risky Business |
| Top Gun |
| 101 Dalmatians |
| Friday the 13th |
| Crocodile Dundee |
+--------------------+
2.
SELECT Title
FROM MOV
ORDER BY Qty DESC ;
Output
+--------------------+
| Title |
+--------------------+
| Top Gun |
| Gone with the Wind |
| Splash |
| Independence Day |
| 101 Dalmatians |
| Friday the 13th |
| Risky Business |
| Cocoon |
| Crocodile Dundee |
| Tootsie |
+--------------------+
3.
SELECT No AS Movie_Number , Price AS Current_Value, (Qty * Price *
1.15) AS Replacement_Value
FROM MOV ;
Output
+--------------+---------------+--------------------+
| Movie_Number | Current_Value | Replacement_Value |
+--------------+---------------+--------------------+
| 1 | 39.95 | 183.77000350952147 |
| 2 | 69.95 | 160.884992980957 |
| 3 | 49.95 | 402.09750614166256 |
| 4 | 29.95 | 103.3275026321411 |
| 5 | 19.95 | 68.8275026321411 |
| 6 | 44.95 | 103.38500175476074 |
| 7 | 31.95 | 73.48500175476073 |
| 8 | 69.95 | 160.884992980957 |
| 9 | 59.95 | 206.8275026321411 |
| 10 | 29.95 | 34.44250087738037 |
+--------------+---------------+--------------------+
Answer
1.
SELECT *
FROM STUDENT1
WHERE Stream = 'Nonmedical' ;
Output
+-----+--------+---------+------------+---------+-------+-------+
| No. | Name | Stipend | Stream | AvgMark | Grade | Class |
+-----+--------+---------+------------+---------+-------+-------+
| 5 | Sabina | 500 | Nonmedical | 90.6 | A | 11A |
| 8 | Rubina | 450 | Nonmedical | 88.5 | A | 12A |
| 9 | Vikas | 500 | Nonmedical | 92.0 | A | 12A |
+-----+--------+---------+------------+---------+-------+-------+
2.
SELECT Name
FROM STUDENT1
WHERE Class LIKE '12%'
ORDER BY Stipend ;
Output
+--------+
| Name |
+--------+
| Divya |
| Mohan |
| Arun |
| Karan |
| John |
| Rubina |
| Vikas |
+--------+
3.
SELECT *
FROM STUDENT1
ORDER BY AvgMark DESC ;
Output
+-----+---------+---------+------------+---------+-------+-------+
| No. | Name | Stipend | Stream | AvgMark | Grade | Class |
+-----+---------+---------+------------+---------+-------+-------+
| 9 | Vikas | 500 | Nonmedical | 92.0 | A | 12A |
| 5 | Sabina | 500 | Nonmedical | 90.6 | A | 11A |
| 2 | Divakar | 450 | Commerce | 89.2 | A | 11C |
| 8 | Rubina | 450 | Nonmedical | 88.5 | A | 12A |
| 1 | Karan | 400 | Medical | 78.5 | B | 12B |
| 6 | John | 400 | Medical | 75.4 | B | 12B |
| 4 | Arun | 350 | Humanities | 73.1 | B | 12C |
| 3 | Divya | 300 | Commerce | 68.6 | C | 12C |
| 10 | Mohan | 300 | Commerce | 67.5 | C | 12C |
| 7 | Robert | 250 | Humanities | 64.4 | C | 11A |
+-----+---------+---------+------------+---------+-------+-------+
4.
SELECT Name, Stipend, Stream, (Stipend * 12) AS Yearly_Stipend
FROM STUDENT1 ;
Output
+---------+---------+------------+----------------+
| Name | Stipend | Stream | Yearly_Stipend |
+---------+---------+------------+----------------+
| Karan | 400 | Medical | 4800 |
| Divakar | 450 | Commerce | 5400 |
| Divya | 300 | Commerce | 3600 |
| Arun | 350 | Humanities | 4200 |
| Sabina | 500 | Nonmedical | 6000 |
| John | 400 | Medical | 4800 |
| Robert | 250 | Humanities | 3000 |
| Rubina | 450 | Nonmedical | 5400 |
| Vikas | 500 | Nonmedical | 6000 |
| Mohan | 300 | Commerce | 3600 |
+---------+---------+------------+----------------+
Answer
1.
SELECT *
FROM CLUB
WHERE SPORTS = 'SWIMMING' ;
Output
+----------+-----------+-----+----------+-----+-----+------------+
| COACH_ID | COACHNAME | AGE | SPORTS | PAY | SEX | DATOFAPP |
+----------+-----------+-----+----------+-----+-----+------------+
| 5 | ZUBIN | 36 | SWIMMING | 750 | M | 1998-01-12 |
| 6 | KETAKI | 36 | SWIMMING | 800 | F | 1998-02-24 |
| 9 | KUSH | 41 | SWIMMING | 900 | M | 1998-01-13 |
+----------+-----------+-----+----------+-----+-----+------------+
2.
SELECT COACHNAME, DATOFAPP
FROM CLUB
ORDER BY DATOFAPP DESC ;
Output
+-----------+------------+
| COACHNAME | DATOFAPP |
+-----------+------------+
| KETAKI | 1998-02-24 |
| ZAREEN | 1998-02-22 |
| ANKITA | 1998-02-20 |
| KARAN | 1998-02-19 |
| SHAILYA | 1998-02-19 |
| RAVINA | 1998-01-20 |
| KUSH | 1998-01-13 |
| ZUBIN | 1998-01-12 |
| TARUN | 1998-01-01 |
| KUKREJA | 1996-03-27 |
+-----------+------------+
3.
SELECT COACHNAME, PAY, AGE, (PAY * 0.15) AS BONUS
FROM CLUB ;
Output
+-----------+------+-----+--------+
| COACHNAME | PAY | AGE | BONUS |
+-----------+------+-----+--------+
| KUKREJA | 1000 | 35 | 150.00 |
| RAVINA | 1200 | 34 | 180.00 |
| KARAN | 2000 | 34 | 300.00 |
| TARUN | 1500 | 33 | 225.00 |
| ZUBIN | 750 | 36 | 112.50 |
| KETAKI | 800 | 36 | 120.00 |
| ANKITA | 2200 | 39 | 330.00 |
| ZAREEN | 1100 | 37 | 165.00 |
| KUSH | 900 | 41 | 135.00 |
| SHAILYA | 1700 | 37 | 255.00 |
+-----------+------+-----+--------+
My SQL Connectivity
Based Program
Table: PRODUCT
P_ ID ProductName Manufacturer Price
TP01 Talcum Powder LAK 40
FW05 Face Wash ABC 45
BS01 Bath Soap ABC 55
SH06 Shampoo XYZ 120
FW12 Face Wash XYZ
The Menu should be:-
(1)Add a record
(2)Display All Records
(3)Displayrecords of a particular
manufacturer.
(4)Modifythe Price of a given P_ID
entered by user.
(5)Delete a Record of given ProductName
(6)Exit.
Source Code:
import mysql.connector as ms
#
cur.execute("insert into product
values('TP01','Talcum Powder','LAK',40)")
con.commit()
if m == 1:
a = input("Enter p_id: ")
b = input("Enter prod_name: ") c
= input("Enter manufacturer: ") d
= int(input("Enter price: "))
print("\nDone!!!\n")
elif m == 2:
print("\n",data1,"\n")
elif m == 3:
print("\n",data2,"\n")
elif m == 4:
print("\nDone!!!\n")
elif m == 6: print("\nYou
have exited...")
break else:
print("\nInvalid Input ... Try Again\n")
con.close()
Output:
Done!!!
Done!!!
Done!!!