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

   Write a Python program

Slip 9 A) Write a Python script using class to reverse a string word by word

Answer :

class MyClass:

    def Get_String(self):

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

    def Reverse_String(self):

        s=self.myStr

        cnt=len(s)

        i=cnt-1

        revStr=""

        while(i >= 0):

            revStr=revStr + s[i]

            i=i-1

            print("String in Reverse:" , revStr)

           

# main body

Obj=MyClass()

Obj.Get_String()

Obj.Reverse_String()

Output :

 

Slip 9 B) Write Python GUI program to accept a number n and check whether it is Prime, Perfect or Armstrong number or not. Specify three radio buttons.

Answer :

def palindrome(n) :

    temp = n

    rev = 0

    while n>0:

        dig = n%10

        rev = rev *10 + dig

        n = n //10

        if temp == rev:

            print(temp,"The Number is a Palindrome !")

        else :

            print(temp,"The Number isn't a Palindrome !")


        def armstrong(n):

            count =0

            temp = n

            while temp>0:

                digit =temp %10

                count += digit **3

                temp//=10

            if(n==count):

                print(n, "is an Armstrong Number")

            else:

                print(n, "is not an Armstrong Number")


        def perfect(n):

            count=0

            for i in range(1,n):

                if n % i==0:

                    count = count +i

            if count ==n:

                print(n,"The Number is a Perfect Number !")

            else :

                print(n,"The Number is Not a Perfect Number !")

        

        if __name__ == '__main__':

            n = int(input("Enter Number : "))

            palindrome(n)

            armstrong(n)

            perfect(n)


Output :

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

No comments:

Powered by Blogger.