Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Python Practical Slip 8 Answers

   Write a Python program

Slip 8 A) Write a python script to find the repeated items of a tuple

Answer :

#Initialize array

t = (1, 2, 3, 4, 2, 7, 8, 8, 3, 2)

print(t)

lst=[]

print("Repeated elements in given tuple ")

#Searches for repeated element

for i in range(0, len(t)):

    if t.count(t[i])>1 :

        if t[i] not in lst:

            lst.append(t[i])

            print(t[i])

Output :

 

Slip 8 B) Write a Python class which has two methods get_String and print_String. get_String accept a string from the user and print_String print the string in upper case. Further modify the program to reverse a string word by word and print it in lower case.

Answer :

class MyClass:

                def Get_String(self):

                                self.MyStr=input("Enter any String: ")

                def Print_String(self):

                                s=self.MyStr

                                print("String in Upper Case: " , s.upper())

                                #String Reverse logic

                                cnt=len(s)

                                i=cnt-1

                                RevStr=""

                                while(i >= 0):

                                                RevStr=RevStr + s[i]

                                                i=i-1

                                print("String in Reverse & Lower case:" , RevStr.lower())

# main body

Obj=MyClass()

Obj.Get_String()

Obj.Print_String()

Output :


Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Python Practical Slip 8 Answers Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Python Practical Slip 8 Answers Reviewed by technical_saurabh on December 31, 2021 Rating: 5

No comments:

Powered by Blogger.