SlideShare a Scribd company logo
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).pdf
keerthu0442
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
BAINIDA
 
Ankita sharma focp
Ankita sharma focpAnkita sharma focp
Ankita sharma focp
AnkitaSharma463389
 
interenship.pptx
interenship.pptxinterenship.pptx
interenship.pptx
Naveen316549
 
Unit-IV Strings.pptx
Unit-IV Strings.pptxUnit-IV Strings.pptx
Unit-IV Strings.pptx
samdamfa
 
C- Programming Assignment 3
C- Programming Assignment 3C- Programming Assignment 3
C- Programming Assignment 3
Animesh Chaturvedi
 
Basic Analysis using Python
Basic Analysis using PythonBasic Analysis using Python
Basic Analysis using Python
Sankhya_Analytics
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdf
srxerox
 
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
vikram mahendra
 
Programming in C Lab
Programming in C LabProgramming in C Lab
Programming in C Lab
Neil Mathew
 
PRACTICAL FILE(COMP SC).pptx
PRACTICAL FILE(COMP SC).pptxPRACTICAL FILE(COMP SC).pptx
PRACTICAL FILE(COMP SC).pptx
AbhinavGupta257043
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
Golden Julie Jesus
 
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.pdf
fedosys
 
paython practical
paython practical paython practical
paython practical
Upadhyayjanki
 
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.pptx
KimVeeL
 

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

Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
veerababupersonal22
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
Kamal Acharya
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 

Recently uploaded (20)

Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 

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)