Yash Raj XII-E Program File
Yash Raj XII-E Program File
Science
Project
File
Submitted by: Submitted to:
Yash Raj Yadav Mrs. Pallavi Sharma
(XII-E) (C.S. TEACHER)
(40)
Index
Sno. Topic
Write code for a function void oddEven (S,N) in
1. python, to add 5 in all the odd values and 10 in all the
even values of the list S
Write a code in python for a function Convert (T,N) ,
2. which repositions all the elements of array by shifting
each of them to next position and shifting first element
to last position?
Write a function SWAP2BEST ( ARR, Size) in
3. 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?
4. WAP to input ‘n’ classes and names of their class
teacher to store them in dictionary and display the
same?
5. Accept a particular class from the user and display the
name of the class teacher of that class? (Let the
dictionary be same as the above question)
Write function definition for SUCCESS (), to read the
6. content of a text file STORY.TXT, and count the
presence of word STORY and display the number of
occurrences of this word?
A text file “STORY.txt” has the following data written
7. in it: Living a life you can be proud of Doing your best
Spending your time with people and activities that are
important to you standing up for things that are right
even when it’s hard Becoming the best version of you.
Write a user defined function to count and display the
total number of words starting with ‘P’ present in a file?
d=[10,14,11,21]
print("Original List",d)
r=len(d)
Convert(d,r)
(OUTPUT)
Original List [10, 14, 11, 21]
after conversion [14, 11, 21, 10]
Q3: 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?
Ans: (Coding)
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]
Q4: WAP to input ‘n’ classes and names of their class teacher to
store them in dictionary and display the same?
Ans: (Coding)
d={}
n=int(input("enter number of classes"))
for i in range(n):
k=input("Enter class ")
d[k]=input("Enter name of class teacher")
print(d)
(Output)
enter number of classes2
Enter class 12-E
Enter name of class teacherMrs Meenakshi sher
Enter class 12-F
Enter name of class teacherMrs Pallavi Sharma
{'12-E': 'Mrs Meenakshi sher', '12-F': 'Mrs Pallavi Sharma'}
Q5: Accept a particular class from the user and display the name of
the class teacher of that class? (Let the dictionary be same as the
above question)
Ans: (Coding)
while True:
h=input("Enter class")
if(h in
d.keys()):
print("Class teacher name is",d[h])
else:
print("Class doesn't exist ")
(Output)
Enter class12-E
Class teacher name is Mrs Meenakshi sher
Enter class12-A
Class doesn't exist
Q6: Write function definition for SUCCESS (), to read the content
of a text file STORY.TXT, and count the presence of word
STORY and display the number of occurrences of this word?
Ans: (Output)
def SUCCESS():
f=open("STORY.txt")
r=f.read()
c=0
for i in r.split():
if(i=="STORY"):
i=i.lower()
c=c+1
print(c)
f.close()
Q7: A text file “STORY.txt” has the following data written in it:
Living a life you can be proud of Doing your best Spending your
time with people and activities that are important to you standing
up for things that are right even when it’s hard Becoming the best
version of you. Write a user defined function to count and display
the total number of words starting with ‘P’ present in a file?
Ans: (Output)
def count():
f=open(“STORY.txt”, “r”)
r=f.read()
n=0
l=r.split()
a=[]
for i in l:
if(i[0]==‘p’):
n=n+1
a.append(i)
else:
continue
print(“total no. of word starting with P are”, n)
print(a)
Q8: Write a Program that reads character from the keyboard one by
one. All lower case characters get store inside the file LOWER, all
upper case characters get stored inside the file UPPER and all other
characters get stored inside OTHERS?
Ans: (coding)
f=open(r"C:\Users\user\Desktop\Story.txt")
f1=open("lower.txt","a")
f2=open("upper.txt","a")
f3=open("others.txt","a")
r=f.read()
for i in r:
if(i>='a' and i<='z'):
f1.write(i)
elif(i>='A' and i<='Z'):
f2.write(i)
else:
f3.write(i)
f.close()
f1.close()
f2.close()
f3.close()
Q9: Write a Program to find no of lines starting with F in
firewall.txt
Ans: (Coding)
f=open(r"C:\Users\hp\Desktop\cs\networking\firewall.txt")
c=0
for i in f.readline():
if(i[0]=='F'):
c=c+1
print(c)
(Output)
3
Q10:Write a Program to find how many ‘firewall’ or ‘to’ are
present in a file firewall.txt?
Ans: (Coding)
f=open(r"C:\Users\user\Desktop\firewall.txt")
t=f.read()
c=0
for i in t.split():
if(i=='firewall')or (i=='is'):
c=c+1
print(c)
(OUTPUT
10
Ans: (Coding)
def writecsv():
f=open("product.csv","w",newline="")
h=['pid','pname','cost','qty']
r=csv.DictWriter(f1,fieldnames=h)
r.writeheader()
while True:
i=int(input("enter id"))
n=input("enter product name")
c=int(input("enter cost"))
q=int(input("enter qty"))
v={'pid':i,'pname':n,'cost':c,'qty':q}
r.writerow(v)
ch=input("more records")
if(ch=='n'):
break
f.close()
Ans: (Coding)
import mysql.connector as m
db=m.connect(host="localhost",user="root",passwd="1234",
database="Em")
c=db.cursor()
c.execute("update emp set sal=sal+100 where job=”clerk”)
db.commit()