0% found this document useful (0 votes)
16 views18 pages

c162 Lab3

Uploaded by

Topchefoframen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views18 pages

c162 Lab3

Uploaded by

Topchefoframen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

SVKM’s NMIMS University

Mukesh Patel School of Technology Management & Engineering


COURSE: Basics of Python Lab Manual
BTI Sem IV Academic Year 2024-2025

Experiment – 1#

Roll No. C162 Name: Kabir Lakhani

Program: BTI Division: D

Semester: IV Batch: D2

Date of Experiment: 28-1-25 Date of Submission:29-1-25

Grade:

B.1. Software Code written by student:


sent=input("Enter the sentence")
Task lenght=len(sent)
1:
a print(sent[::-1])

b word=input("Enter the word ")

print(word[::2])

c word=input("Enter the word ")

chara=input("Enter the letter u want to check ")

print(word.startswith(chara))

d sent="""hello

world """

print(sent.replace('\n',''))

e word=input("Enter the string ")

chara=input("Enter the letter u want to remove ")

chara_replace=input("Enter the character with which u want to replace ")

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=[',','.','?','!',':',';']

sent=input("Enter the string ")

for p in punct:

sent=sent.replace(p,'')

print(sent)

g sent1=input("Enter the first string ")

sent2=input("Enter the second string ")

chara=input("Enter the letter u want to search ")

if(sent1.count(chara)>=sent2.count(chara)):

print(f"there are {sent2.count(chara)} characters that are common")

elif(sent1.count(chara)<sent2.count(chara)):

print(f"there are {sent1.count(chara)} characters that are common")

h sent=input("Enter the string ")

list_str=[]

list_str.extend(sent)

print(list_str)

i sent=input("Enter the numbers ")

int_list=[]

for x in sent:

int_list.append(int(x))

print(int_list)

j sent=input("Enter the sentence ")

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

print(f"Upper count is {count_upper} and lower count is {count_lower}")

k vowels=['a','e','i','o','u']

sent=input("Enter the string ")

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)

m sent=input("Enter the string ")

print(sent.upper())

print(sent.lower())

n num=int(input("Enter the number"))

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

Task sent=input("Enter a string ")


2:
sent=sent.replace(" ","#")

print(sent)

Task sent1=input("Enter the first string ")


3:
sent2=input("Enter the second string ")

sent1.lower()

sent2.lower()

list1=[]

list2=[]

list1=sent1.split()

list2=sent2.split()

for x in list1:

if(x in list2):

print(x)

Task sent=input("Enter your string ")


4:
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'):

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

print(f"No of a is {count_a}\nNo of e is {count_e}\nNo of i is {count_i}\nNo of o is


{count_o}\nNo of u is {count_u}")

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)

x=input("Enter the number of u want it to search")

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

print(f"{x} appeares {count} times in the list")

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):

temp=int(input("Enter the elements"))

list.append(temp)

y=int(input("Enter the value you want to search"))

count=0

for x in list:

if(y==x):

count+=1

print(f"The vlaue {y} appears {count} times")

Task list=[]
7:
n=int(input("Enter the number of elements "))

for i in range(0,n):

temp_1=(input(f"Enter the element no {i+1}"))

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

n=int(input("Enter the number of elements "))

for i in range(0,n):

temp_1=int(input(f"Enter the element no {i+1}"))

list.append(temp_1)

for x in list:

if(x>0):

count_p+=1

elif(x<0):

count_n+=1

else:

count_0+=1

print(f"The number of positive numbers is {count_p}, negatvie nos is {count_n} and no


of zeroes is {count_0}")

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

temp=int(input(f"Enter the element number {i+1} "))

list.append(temp)

sum=0

for x in list:

sum+=x

print("The sum of all elements is",sum)

Task list=[]
10:
list_2=[]

l=int(input("Enter the number of elemets "))

for i in range(0,l):

temp=input(f"Enter the element {i+1} ")

list.append(temp)

n=int(input("Enter the minimum size of the words "))

for x in list:

if(len(x)>=n):

list_2.append(x)

print(list_2)

Task list1=["red", "orange", "green", "blue", "white"]


11:
list2=["black", "yellow", "green", "blue"]

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):

temp=(input(f"Enter the element number {i+1} "))

list.append(temp)

string=''

for x in list:

string=string+x

print(string)

Task list=[]
13
list2=[]

n=int(input("Enter the no of elements "))

for i in range(0,n):

temp=(input(f"Enter the element number {i+1} "))

list.append(temp)

str=input("Enter the string ")

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

B.2 Input and Output:

Task
1:
a

Figure 1-Task 1-A

Figure 2-Task 1-B

Figure 3-Task 1-C

Figure 4-Task 1-D

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

Figure 5-Task 1-E

Figure 6-Task 1-F

Figure 7-Task 1-G

Figure 8-Task 1-H

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

Figure 9-Task 1-I

Figure 10-Task 1-J

Figure 11-Task 1-K

Figure 12-Task 1-L

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

Figure 13-Task 1-M

Figure 14-Task 1-N

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

You might also like