Anshul Rana - Program File
Anshul Rana - Program File
PROGRAM 2 : WAP to remove all odd numbers from the given list.
PROGRAM 3 : Write a program to find and display the sum of all the values which are ending with 3 from a list
PROGRAM 4 : Write a program to accept values from a user and create a tuple
PROGRAM 5 : Write a program to find and display the sum of all the values which are ending with 3 from a list
PROGRAM 6 : Write a program to show all non -prime numbers in the entered range .
PROGRAM 7 : Write a program to find factorial of entered number using library function fact().
PROGRAM 8 : Program20 : Write a program to show and count the number of words in a text file ‘DATA.TXT’ which
is starting/ended with an word ‘The’, ‘the’, ‘my’, ‘he’, ‘they’
PROGRAM 9 : Write a program to read data from a text file DATA.TXT, and display each words with number of
vowels and consonants.
INDEX
PROGRAM 10 : Write a program to insert list data in CSV File and print it.
PROGRAM 11 : Write a program that rotates the elements of a list so that the element at the first index moves
to the second index, the element in the second index moves to the third
index, etc., and the element in the last index moves to the first index.
PROGRAM 12 : Write a program to show push and pop operation using stack
PROGRAM 13 : Write a program to show MySQL CONNECTIVITY for inserting two tuples in table:"student"
inside database:"class12" .
PROGRAM 14 : Write a program to call great func() to find greater out of entered two numbers, using
import command .
PROGRAM 15 : Write a program that will write a string binary file "school.dat" and display the words of
the string in reverse order.
PROGRAM 16 :Write a program to insert item on selected position in list and print the updated list.
PROGRAM 1:WAP TO ACCEPT A STRING AND WHETHER IT IS A
PALINDROME OR NOT.
str=input("enter the string")
l=len(str)
p=l-1
index=0
while(index<p):
if(str[index]==str[p]):
index=index+1
p=p-1
else:
print("string is not a palindrome") OUTPUT:
break enter a string : NITIN
else: string is palindromee
print("string is palindrome")
PROGRAM 2:WAP TO REMOVE ALL ODD NUMBERS FROM THE
GIVEN LIST.
L=[2,7,12,5,10,15,23]
for i in L:
if i%2==0:
L.remove(i) OUTPUT:
print(L) [7,5,15,23]
PROGRAM 3:WAP TO FIND AND DISPLAY THE SUM OF ALL THE
VALUES WHICH ARE ENDING WITH 3 FROM A LIST
L=[33,13,92,99,3,12]
sum=0
x=len(L)
for i in range(0,x): OUTPUT:
if type(L[i])==int: 49
if L[i]%10==3:
sum+=L[i]
print(sum)
PROGRAM4: WRITE A PROGRAM TO ACCEPT VALUES FROM A USER
AND CREATE A TUPLE.
t=tuple()
n=int(input("enter limit:"))
for i in range(n):
a=input("enter number:")
t=t+(a,)
print("output is")
print(t)
PROGRAM 5:WAP TO FIND AND DISPLAY THE SUM OF ALL THE
VALUES WHICH ARE ENDING WITH 3 FROM A LIST.
L=[33,13,92,99,3,12]
sum=0
x=len(L)
for i in range(0,x): OUTPUT:6
if type(L[i])==int:
if L[i]%10==3:
sum+=L[i]
print(sum)
PROGRAM 6: WRITE A PROGRAM TO SHOW ALL NON -PRIME
NUMBERS IN THE ENTERED RANGE
def nprime(lower,upper):
print("“SHOW ALL NUMBERS EXCEPT PRIME NUMBERS WITHIN THE RANGE”")
for i in range(lower, upper+1): OUTPUT:
for j in range(2, i): Enter lowest number as lower bound to check : 3
Enter highest number as upper bound to check : 41
ans = i % j SHOW ALL NUMBERS EXCEPT PRIME
NUMBERS WITHIN THE RANGE if ans==0:
4,6,8,10,12,14,18,20,22,24,26,28,30,32,34,36,38,40 NONE
print (i,end=' ')
break
lower=int(input("Enter lowest number as lower bound to check : "))
upper=int(input("Enter highest number as upper bound to check: "))
reply=nprime(lower,upper)
print(reply)
PROGRAM 7 : WRITE A PROGRAM TO FIND FACTORIAL OF
ENTERED NUMBER USING LIBRARY FUNCTION FACT().
def fact(n):
if n<2:
return 1 OUTPUT:
else : ENTER VALUE FOR FACTORIAL: 12
the factorial of the number is :479001600
return n*fact(n-1)
import factfunc
x=int(input("Enter value for factorial : "))
ans=factfunc.fact(x)
print (ans)
PROGRAM 8 : WRITE A PROGRAM TO SHOW AND COUNT THE
NUMBER OF WORDS IN A TEXT FILE ‘DATA.TXT’ WHICH IS
STARTING/ENDED WITH AN WORD ‘THE’, ‘THE’, ‘MY’, ‘HE’, ‘THEY’
f1=open("data.txt","r")
s=f1.read()
print("All Data of file in string : \n",s)
print("="*30)
count=0
words=s.split()
print("All Words: ",words,", length is ",len(words))
for word in words:
if word.startswith("the")==True: # word.ends with(“the”)
count+=1
print("Words start with 'the' is ",count)
PROGRAM 9 : WRITE A PROGRAM TO READ DATA FROM A TEXT
FILE DATA.TXT, AND DISPLAY EACH WORDS WITH NUMBER OF
VOWELS AND CONSONANTS.
f1=open("data.txt","r")
s=f1.read()
print(s)
countV=0
countC=0
words=s.split()
print(words,", ",len(words))
for word in words:
countV=0
countC=0
for ch in word:
if ch.isalnum()==True:
if ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u':
countV+=1
else:
countC+=1
print("Word : ",word,", V: ",countV,", C= ", countC)
PROGRAM 10 : WRITE A PROGRAM TO INSERT LIST DATA IN CSV
FILE AND PRINT IT.
import csv
fields = ['Name', 'Branch', 'Year', 'CGPA'] # field names
# data rows of csv file
rows = [ ['Nikhil', 'COE', '2', '9.0'],
['Sanchit', 'COE', '2', '9.1'],
['Aditya', 'IT', '2', '9.3'],
['Sagar', 'SE', '1', '9.5'],
['Prateek', 'MCE', '3', '7.8'],
['Sahil', 'EP', '2', '9.1']]
filename = "MYCSV.csv"
with open(filename, 'w') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(fields)
csvwriter.writerows(rows)
with open('MYCSV.csv', newline='') as File:
reader = csv.reader(File)
for row in reader:
print(row)
PROGRAM 11 : WRITE A PROGRAM THAT ROTATES THE ELEMENTS OF A LIST SO
THAT THE ELEMENT AT THE FIRST INDEX MOVES TO THE SECOND INDEX, THE
ELEMENT IN THE SECOND INDEX MOVES TO THE THIRD
INDEX, ETC., AND THE ELEMENT IN THE LAST INDEX MOVES TO THE FIRST
INDEX.
n=int(input("Enter Number of items in List: "))
DATA=[]
for i in range(n):
item=int(input("Item :%d: "%(i+1)))
DATA.append(item)
print("Now List Items are :",DATA)
lg=len(DATA)
print("Now Number of items before update are :",lg)
b=["undef"]*lg
for x in (range(lg-1)):
if (x)>lg:
break
b[x+1]=DATA[x]
b[0]=DATA[-1]
print("RESULT OF NEW LIST IS " , b)
PROGRAM 13 : WRITE A PROGRAM TO SHOW PUSH AND POP
OPERATION USING STACK
import mysql.connector as m
db=m.connect(host="localhost",user="root",passwd="h",database="class12")
cursor_obj=db.cursor()
cursor_obj.execute("INSERT INTO student(admno,name,class,sec,rno,address)VALUES({},'{}','{}','{}',
{},'{}')".format(1236,"kamala",11,'a',43,"NARELA"))
cursor_obj.execute("INSERT INTOstudent(admno,name,class,sec,rno,address)VALUES({},'{}','{}','{}',
{},'{}')".format(1237,"kishore",12,'c',3,"NARELA"))
db.commit()
print("record inserted")
cursor_obj.execute("select * from student")
data=cursor_obj.fetchall()
for row in data:
print(row)
PROGRAM 18 : WRITE A PROGRAM TO CALL GREAT FUNC() TO
FIND GREATER OUT OF ENTERED TWO NUMBERS, USING IMPORT
COMMAND .
f1=open('school.dat','rb')
str1=pickle.load(f1)
print("\n\nthe string in the binary file is : \n",str1)
str1=str.split(" ")
l=list(str1)
print("\nthe list is ",l)
length=len(l)
while length>0:
print(l[length-1],end=" ")
length-=1
PROGRAM 20 :WRITE A PROGRAM TO INSERT ITEM ON SELECTED
POSITION IN LIST AND PRINT THE UPDATED LIST.
n=int(input("Enter Number of items in List: "))
DATA=[]
for i in range(n):
item=int(input("Item :%d: "%(i+1)))
DATA.append(item)
print("Now List Items are :",DATA)
print("Now Number of items before update are :",len(DATA)) OUTPUT:
e=int(input("Enter Item = ")) enter the number of items in list: 4
pos=int(input("Enter POS = ")) item: 1 :2
DATA.append(None) item: 1 :4
item: 1 :6
item: 1 :8
le=len(DATA) new list items are :[2,4,6,8]
for i in range(le-1,pos-1,-1): no of items before updating are : 4
DATA[i]=DATA[i-1] enter item : 3
print("Now List Items are :",DATA) enter POS = 2
DATA[pos-1]=e now list of items are :5
print("Now Number of items are :",len(DATA)) now updated list items are : [2,3,4,6,8]
print("Now Updated List Items are :",DATA)