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

   Write a Python program

Slip  5 A) Write a Python script using 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.

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

# main body

Obj=MyClass()

Obj.Get_String()

Obj.Print_String()

Output :

 

Slip 5  B) Write a python script to generate Fibonacci terms using generator function.

Answer :

def Fibo(terms2):

    f1=0

    yield f1

    f2=1

    yield f2

for i in range(0,terms2-2):

    f3=f1+f2

    yield f3

    f1=f2

    f2=f3

#mainbody

terms1=int(input("How many terms:"))

gen=Fibo(terms1)

while True:

    try:

        print(next(gen))

    except StopIteration:

        break

Output :

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

No comments:

Powered by Blogger.