SlideShare a Scribd company logo
1 of 19
PYTHON PROGRAM
FILE
BY: ANSHUL RANA
XII E
ROLL NO : 8
INDEX
PROGRAM 1 : Write a program to show entered string is a palindrome or not.
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
def push(stack,x): #function to add element at the end of list
stack.append(x)
def pop(stack): #function to remove last element from list
n = len(stack)
if(n<=0):
print("Stack empty....Pop not possible")
else:
stack.pop()
def display(stack): #function to display stack entry
if len(stack)<=0:
print("Stack empty...........Nothing to display")
for i in stack:
print(i,end=" ")
#main program starts from here
x=[]
choice=0
while (choice!=4):
print("********Stack Menu***********")
print("1. push(INSERT)")
print("2. pop(DELETE)")
print("3. Display ")
print("4. Exit")
choice = int(input("Enter your choice :"))
if(choice==1):
value = int(input("Enter value "))
push(x,value)
if(choice==2):
pop(x)
if(choice==3):
display(x)
if(choice==4):
PROGRAM 15: WRITE A PROGRAM TO SHOW MYSQL
CONNECTIVITY FOR INSERTING TWO TUPLES IN
TABLE:"STUDENT" INSIDE DATABASE:"CLASS12" .
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 .
def chknos(a, b):
if a>b:
print("the first number ",a,"is greater") OUTPUT:
return a ENTER FIREST NUMBER : 74
else: ENTER SECOND NUMBER: 34
print("the second number ",b,"is greater") THE FIREST NUMBER 74 is greater
return b greatest number = 67
import greatfunc
a=int(input("Enter First Number : "))
b=int(input("Enter Second Number : "))
ans=greatfunc.chknos(a, b)
print("GREATEST NUMBER = ",ans)
PROGRAM 19 : WRITE A PROGRAM THAT WILL WRITE A STRING
BINARY FILE "SCHOOL.DAT" AND DISPLAY THE WORDS OF THE
STRING IN REVERSE ORDER.
f1=open('school.dat','rb')
str1=pickle.load(f1)
print("nnthe 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)

More Related Content

Similar to ANSHUL RANA - PROGRAM FILE.pptx

python_lab_manual_final (1).pdf
python_lab_manual_final (1).pdfpython_lab_manual_final (1).pdf
python_lab_manual_final (1).pdfkeerthu0442
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshopBAINIDA
 
Unit-IV Strings.pptx
Unit-IV Strings.pptxUnit-IV Strings.pptx
Unit-IV Strings.pptxsamdamfa
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdfsrxerox
 
project report in C++ programming and SQL
project report in C++ programming and SQLproject report in C++ programming and SQL
project report in C++ programming and SQLvikram mahendra
 
Programming in C Lab
Programming in C LabProgramming in C Lab
Programming in C LabNeil Mathew
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in cgkgaur1987
 
Create a C program which auto-completes suggestions when beginning t.pdf
Create a C program which auto-completes suggestions when beginning t.pdfCreate a C program which auto-completes suggestions when beginning t.pdf
Create a C program which auto-completes suggestions when beginning t.pdffedosys
 
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...Yashpatel821746
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Yashpatel821746
 
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...Yashpatel821746
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptxKimVeeL
 

Similar to ANSHUL RANA - PROGRAM FILE.pptx (20)

python_lab_manual_final (1).pdf
python_lab_manual_final (1).pdfpython_lab_manual_final (1).pdf
python_lab_manual_final (1).pdf
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
 
Ankita sharma focp
Ankita sharma focpAnkita sharma focp
Ankita sharma focp
 
interenship.pptx
interenship.pptxinterenship.pptx
interenship.pptx
 
Unit-IV Strings.pptx
Unit-IV Strings.pptxUnit-IV Strings.pptx
Unit-IV Strings.pptx
 
C- Programming Assignment 3
C- Programming Assignment 3C- Programming Assignment 3
C- Programming Assignment 3
 
Basic Analysis using Python
Basic Analysis using PythonBasic Analysis using Python
Basic Analysis using Python
 
Muzzammilrashid
MuzzammilrashidMuzzammilrashid
Muzzammilrashid
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdf
 
project report in C++ programming and SQL
project report in C++ programming and SQLproject report in C++ programming and SQL
project report in C++ programming and SQL
 
Programming in C Lab
Programming in C LabProgramming in C Lab
Programming in C Lab
 
PRACTICAL FILE(COMP SC).pptx
PRACTICAL FILE(COMP SC).pptxPRACTICAL FILE(COMP SC).pptx
PRACTICAL FILE(COMP SC).pptx
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 
Create a C program which auto-completes suggestions when beginning t.pdf
Create a C program which auto-completes suggestions when beginning t.pdfCreate a C program which auto-completes suggestions when beginning t.pdf
Create a C program which auto-completes suggestions when beginning t.pdf
 
paython practical
paython practical paython practical
paython practical
 
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
 
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
 

Recently uploaded

(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 

Recently uploaded (20)

(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 

ANSHUL RANA - PROGRAM FILE.pptx

  • 1. PYTHON PROGRAM FILE BY: ANSHUL RANA XII E ROLL NO : 8
  • 2. INDEX PROGRAM 1 : Write a program to show entered string is a palindrome or not. 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.
  • 3. 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.
  • 4. 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")
  • 5. 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]
  • 6. 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)
  • 7. 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)
  • 8. 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)
  • 9. 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)
  • 10. 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)
  • 11. 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)
  • 12. 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)
  • 13. 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)
  • 14. 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)
  • 15. PROGRAM 13 : WRITE A PROGRAM TO SHOW PUSH AND POP OPERATION USING STACK def push(stack,x): #function to add element at the end of list stack.append(x) def pop(stack): #function to remove last element from list n = len(stack) if(n<=0): print("Stack empty....Pop not possible") else: stack.pop() def display(stack): #function to display stack entry if len(stack)<=0: print("Stack empty...........Nothing to display") for i in stack: print(i,end=" ") #main program starts from here x=[] choice=0 while (choice!=4): print("********Stack Menu***********") print("1. push(INSERT)") print("2. pop(DELETE)") print("3. Display ") print("4. Exit") choice = int(input("Enter your choice :")) if(choice==1): value = int(input("Enter value ")) push(x,value) if(choice==2): pop(x) if(choice==3): display(x) if(choice==4):
  • 16. PROGRAM 15: WRITE A PROGRAM TO SHOW MYSQL CONNECTIVITY FOR INSERTING TWO TUPLES IN TABLE:"STUDENT" INSIDE DATABASE:"CLASS12" . 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)
  • 17. PROGRAM 18 : WRITE A PROGRAM TO CALL GREAT FUNC() TO FIND GREATER OUT OF ENTERED TWO NUMBERS, USING IMPORT COMMAND . def chknos(a, b): if a>b: print("the first number ",a,"is greater") OUTPUT: return a ENTER FIREST NUMBER : 74 else: ENTER SECOND NUMBER: 34 print("the second number ",b,"is greater") THE FIREST NUMBER 74 is greater return b greatest number = 67 import greatfunc a=int(input("Enter First Number : ")) b=int(input("Enter Second Number : ")) ans=greatfunc.chknos(a, b) print("GREATEST NUMBER = ",ans)
  • 18. PROGRAM 19 : WRITE A PROGRAM THAT WILL WRITE A STRING BINARY FILE "SCHOOL.DAT" AND DISPLAY THE WORDS OF THE STRING IN REVERSE ORDER. f1=open('school.dat','rb') str1=pickle.load(f1) print("nnthe 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
  • 19. 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)