c162 Lab3
c162 Lab3
Experiment – 1#
Semester: IV Batch: D2
Grade:
print(word[::2])
print(word.startswith(chara))
d sent="""hello
world """
print(sent.replace('\n',''))
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(word.replace(chara,chara_replace))
f punct=[',','.','?','!',':',';']
for p in punct:
sent=sent.replace(p,'')
print(sent)
if(sent1.count(chara)>=sent2.count(chara)):
elif(sent1.count(chara)<sent2.count(chara)):
list_str=[]
list_str.extend(sent)
print(list_str)
int_list=[]
for x in sent:
int_list.append(int(x))
print(int_list)
count_upper=0
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
count_lower=0
for x in sent:
if(x.isupper()):
count_upper+=1
elif(x.islower()):
count_lower+=1
k vowels=['a','e','i','o','u']
count=0
sent=sent.lower()
for x in sent:
if(x in vowels):
print(x,end=" ")
l sent=["hi","world","sup?"]
sent.sort()
print(sent)
print(sent.upper())
print(sent.lower())
strings=str(num)
print(strings)
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
print(sent)
sent1.lower()
sent2.lower()
list1=[]
list2=[]
list1=sent1.split()
list2=sent2.split()
for x in list1:
if(x in list2):
print(x)
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'):
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
count_e+=1
elif(x=='i'):
count_i+=1
elif(x=='o'):
count_o+=1
elif(x=='u'):
count_u+=1
Task bill_details=["2000","1230","8000"]
5:
bill_details.append("12000")
print(bill_details)
bill_details[1]=1200
print(bill_details)
bill_details.remove(1200)
print(bill_details)
bill_details.clear()
print(bill_details)
bill_details=["2000","1230","8000","120409"]
print(bill_details[0:2])
bill_details.pop(2)
print(bill_details)
count=0
for y in bill_details:
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
if(y==x):
count+=1
bill_details.sort()
print(bill_details)
print(bill_details[-1::-1])
Task list=[]
6:
n=int(input("Enter the number of elements "))
for i in range(0,n):
list.append(temp)
count=0
for x in list:
if(y==x):
count+=1
Task list=[]
7:
n=int(input("Enter the number of elements "))
for i in range(0,n):
list.append(temp_1)
temp=[]
for x in list:
if(x in temp):
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
continue
print(x)
temp.append(x)
Task list=[]
8:
count_p=0
count_n=0
count_0=0
for i in range(0,n):
list.append(temp_1)
for x in list:
if(x>0):
count_p+=1
elif(x<0):
count_n+=1
else:
count_0+=1
Task list=[]
9:
n=int(input("Enter the no of elements "))
for i in range(0,n):
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
list.append(temp)
sum=0
for x in list:
sum+=x
Task list=[]
10:
list_2=[]
for i in range(0,l):
list.append(temp)
for x in list:
if(len(x)>=n):
list_2.append(x)
print(list_2)
temp1=[]
temp1=list1.copy()
for x in list2:
for y in list1:
if(y==x):
list1.remove(y)
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("colour1-colour2=",list1)
for x in temp1:
for y in list2:
if(y==x):
list2.remove(y)
print("colour2-colour1=",list2)
Task list=[]
12:
n=int(input("Enter the no of elements "))
for i in range(0,n):
list.append(temp)
string=''
for x in list:
string=string+x
print(string)
Task list=[]
13
list2=[]
for i in range(0,n):
list.append(temp)
for x in list:
temp=str+x
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
list2.append(temp)
print(list2)
Task list_2d=[1,2,3],[4,5,6],[10,20,30],[3,3,3]
14
sums=[]
for x in list_2d:
sum=0
for y in x:
sum+=y
sums.append(sum)
maximum=max(sums)
index=sums.index(maximum)
print(list_2d[index][::])
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
Task
1:
a
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
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
2:
Figure 15-Task 2
Task
3:
Figure 16-Task 3
Task
4:
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
Figure 17-Task 4
Task
5:
Figure 18-Task 5
Task
6:
Figure 19-Task 6
Task
7:
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
Figure 20-Task 7
Task
8:
Figure 21-Task 8
Task
9;
Figure 22-Task 9
Task
10:
Figure 23-Task 10
Task
11:
16
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Basics of Python Lab Manual
BTI Sem IV Academic Year 2024-2025
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 about strings, string functions, lists, list functions, 1d and 2d lists.
17
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Basics of Python Lab Manual
BTI Sem IV Academic Year 2024-2025
18