Part B Format python
Part B Format python
Experiment – 3
Semester: IV Batch: D2
Grade:
1
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Basics of Python Lab Manual
BTI Sem IV Academic Year 2024-2025
print(string.startswith(char))
sentence="""Python
d basics """
print(sentence.replace('\n',''))
print(string.replace(char,char_1))
punctuations=[',','.','?','!']
f sentence=input("Enter string ")
for x in punctuations:
sentence=sentence.replace(x,'')
print(sentence)
if(sentence1.count(char)>=sentence2.count(char)):
elif(sentence1.count(char)<sentence2.count(char)):
2
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Basics of Python Lab Manual
BTI Sem IV Academic Year 2024-2025
list.extend(sentence)
print(list)
for x in sentence:
list.append(int(x))
print(list)
count_l=0
for x in string:
if(x.isupper()):
count_u=count_u+1
elif(x.islower()):
count_l=1+count_l
vowels=['a','e','i','o','u']
k string=input("Enter string ")
string=string.lower()
for x in string:
if(x in vowels):
print(x,end=" ")
list=["banana","apple","dragon","cheese"]
l list.sort()
print(list)
3
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Basics of Python Lab Manual
BTI Sem IV Academic Year 2024-2025
number=int(input("Enter number"))
n string=str(number)
str2=str1.replace(' ','#')
str2="basics of python"
str1.lower()
str2.lower()
words1=str1.split()
words2=str2.split()
common_words=[]
if word in words2:
common_words.append(word)
if common_words:
else:
4
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Basics of Python Lab Manual
BTI Sem IV Academic Year 2024-2025
sent=sent.lower()
count_a=0
count_e=0
count_i=0
count_o=0
count_u=0
for x in sent:
if(x=='a'):
count_a+=1
elif(x=='e'):
count_e+=1
elif(x=='i'):
count_i+=1
elif(x=='o'):
count_o+=1
elif(x=='u'):
count_u+=1
5
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Basics of Python Lab Manual
BTI Sem IV Academic Year 2024-2025
Task 5: bill=["234","546","9532"]
bill.append("1234")
print(bill)
bill[1]=1200
print(bill)
bill.remove(1200)
print(bill)
bill.clear()
print(bill)
bill=["234","546","9532","12345"]
print(bill[0:2])
bill.pop(2)
print(bill)
count=0
for y in bill:
if(y==x):
count+=1
bill.sort()
print(bill)
print(bill[-1::-1])
Task 6: list=["abc","12","simone","yo","12","abc"]
count=0
6
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Basics of Python Lab Manual
BTI Sem IV Academic Year 2024-2025
for x in list:
if(search==x):
count+=1
Task 7: list=["1","1","1","2","2","3","5"]
temp=[]
for x in list:
if(x in temp):
continue
print(x,end=" ")
temp.append(x)
Task 8: list=[-9,-3,2,3,0,-2]
count_pos=0
count_neg=0
for x in list:
if(x>0):
count_pos+=1
elif(x<0):
count_neg+=1
Task 9: list=[1,2,3,4,5]
sum=0
for x in list:
sum+=x
7
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Basics of Python Lab Manual
BTI Sem IV Academic Year 2024-2025
Task list=["hi","cheese","yo","hey","burger"]
10:
list2=[]
for x in list:
if(len(x)>=n):
list2.append(x)
print(list2)
temp1=[]
temp1=list1.copy()
for x in list2:
for y in list1:
if(y==x):
list1.remove(y)
print("colour1-colour2=",list1)
for x in temp1:
for y in list2:
if(y==x):
list2.remove(y)
print("colour2-colour1=",list2)
Task list=["1","2","3","Simone"]
12:
string=''
for x in list:
string=string+x
8
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Basics of Python Lab Manual
BTI Sem IV Academic Year 2024-2025
print(string)
Task list=["1","2","3"]
13:
list_2=[]
for x in list:
temp=string+x
list_2.append(temp)
print(list_2)
Task list2d=[1,1,1],[3,3,3,],[4,4,4,],[2,2,2]
14:
sums=[]
for x in list2d:
sum=0
for y in x:
sum+=y
sums.append(sum)
maximum=max(sums)
index=sums.index(maximum)
9
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Basics of Python Lab Manual
BTI Sem IV Academic Year 2024-2025
Task 1:
a
10
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Basics of Python Lab Manual
BTI Sem IV Academic Year 2024-2025
11
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Basics of Python Lab Manual
BTI Sem IV Academic Year 2024-2025
12
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Basics of Python Lab Manual
BTI Sem IV Academic Year 2024-2025
Task 2:
Figure 15-Task 2
Task 3:
Figure 16-Task 3
Task 4:
Figure 17-Task 4
13
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Basics of Python Lab Manual
BTI Sem IV Academic Year 2024-2025
Task 5:
Figure 18-Task 5
Task 6:
Figure 19-Task 6
Task 7:
Figure 20-Task 7
Task 8:
Figure 21-Task 8
Task 9:
Figure 22-Task 9
14
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Basics of Python Lab Manual
BTI Sem IV Academic Year 2024-2025
Task
10:
Figure 23-Task 10
Task
11:
Figure 24-Task 11
Task
12:
Figure 25-Task 12
Task
13:
Figure 26-Task 13
Task
14:
Figure 27-Task 14
B.3 Conclusion:
We learnt advanced topic like lists, appending, string, string functions etc.
15
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Basics of Python Lab Manual
BTI Sem IV Academic Year 2024-2025
16