myString = "hello! \n welcome to Python class on STRINGS. \n This is our 2nd LaB."
print(myString)
hello!
welcome to Python class on STRINGS.
This is our 2nd LaB.
Task 1
built in functions
print("Datatype - ",type(myString))
print("Length of string is ",len(myString))
print("Position of 'P' is ",myString.find('P'))
print("Replacing..")
myString = myString.replace('w','W')
print(myString)
myString.endswith('aB.')
print("Resultant string is: \n %s "%(myString))
Datatype - <class 'str'> //the Datatype of mystring
Length of string is 67 //Length of string
Position of 'P' is 20 //postion where p is found
Replacing..
hello! Welcome to Python class on STRINGS. This is our 2nd LaB.//replacing w with W
True//string endswith aB.
Resultant string is://printing in new line after fullstop
hello!
Welcome to Python class on STRINGS.
This is our 2nd LaB.
Task 2
print("Fifth letter of the string is",myString[4])#index operators
print("Last letter is",myString[-1])
print("Sliced string is",myString[3:10])
print("One more reversed",myString[4:10:2])
if(myString.isalpha()==True) or (myString.isdigit()==True):#logical OR operator
print("Alphabet Or Digit")
else: print("None")
if("i" in myString):#membership operator
print("Letter i is in the given string")
elif("i" not in myString):
print("Letter i is not in the given string")
a="hi"#identity operator
b="Hi"
if(a is b):
print("Hii")
elif(a is not b):
print("Bye")
combine=a+myString print(combine)#concatenation
Fifth letter of the string is o
Last letter is .
Sliced string is lo!
W
One more reversed o
None
Letter i is in the given string
Bye
hihello! Welcome to Python class on STRINGS. This is our 2nd LaB.
#Task 3 name place animal things
nn = input("Enter the number of players: ")
n= int(nn)
letter = input("Participant 1 give a letter")
i=0
name = []n
place = []n
animal = []n
things = []n
while(i<n):
print("Participant",i+1)
na=input("Name : ")
name.append(na)
pla=input("Place : ")
place.append(pla)
ani=input("Animal :")
animal.append(ani)
thi=input("Thing : ")
things.append(thi)
i=i+1
j=0
k=0
l=0
m=0
for x in name:
print("Player ",j+1)
if (x.startswith(letter)==True):
print("Name is right")
else:
print("Name is wrong")
j=j+1 for x in place:
print("Player",k+1)
if (x.startswith(letter)==True):
print("Place is right")
else:
print("Place is wrong")
k=k+1
for x in animal:
print("Player",l+1)
if (x.startswith(letter)==True):
print("Animal is right")
else:
print("Animal is wrong")
l=l+1 for x in things:
print("Player",m+1)
if (x.startswith(letter)==True):
print("Thing is right")
else:
print("Thing is wrong")
m=m+1
Enter the number of players: 3
Participant 1 give a letterh
Participant 1
Name : hritik
Place : home
Animal :horse
Thing : handgun
Participant 2
Name : homie
Place : himachal
Animal :monkey
Thing : holder
Participant 3
Name : carry
Place : minati
Animal :tik
Thing : tok
Player 1 Name is right
Player 2 Name is right
Player 3 Name is wrong
Player 1 Place is right
Player 2 Place is right
Player 3 Place is wrong
Player 1 Animal is right
Player 2 Animal is wrong
Player 3 Animal is wrong
Player 1 Thing is right
Player 2 Thing is right
Player 3 Thing is wrong
#Task 4 madlib
print("Hello World! Lets Play Madlib game")
color = input("Enter color: ")
pluralnoun = input("Enter plural noun: ")
celebrity = input("Enter celebrity: ")
print("\nRoses are",str(color))
print("\n"+str(pluralnoun),"are blue")
print("\nI love",str(celebrity))
Hello World! Lets Play Madlib game
Enter color: Red
Enter plural noun: Clouds
Enter celebrity: Disha
Roses are Red
Clouds are blue
I love Disha
The Journey Begins
Thanks for joining me!
Good company in a journey makes the way seem shorter. — Izaak Walton
