You are on page 1of 2

Name : Hariharan A

Roll NO: 20BEC034


Subject Code & Name : U18CSI2201L Python Programming
1) Write a program (using functions) that takes a long sentence with multiple words as input
and rearranges the words in the sentence in the reverse order.
Test Case 1
Input : I am a Good Boy
Output : Boy Good a am I
Code :

def reverseorder(str):
i = len(str)-1
firstword = lastword = i+1
result = ''

while i>=0:
if str[i] == ' ':
firstword = i+1
while firstword!= lastword:
result += str[firstword]
firstword+=1
result+=' '
lastword = i
i-=1
firstword = 0
while firstword!=lastword:
result+=str[firstword]
firstword+=1
return result
#input
str = 'I am a Good Boy'
print(reverseorder(str))
Output :

2) Write a function to check whether a list contains duplicate elements. It should return True
if the list contains duplicate elements and False if list does not contain duplicate elements.
Code :

def duplicatecheck(listOfElements):
for elemt in listOfElements:
if listOfElements.count(elemt) > 1:
return True
return False
listOfElements = ['Hello', 'Ok', 'is', 'test', 'this']
result = duplicatecheck(listOfElements)
if result:
print ("True")
else:
print ("False")

Output :

You might also like