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

   Write a Python program

Slip 19 A) Write a Python GUI program to accept a number form user and display its multiplication table on button click.

Answer :


from tkinter import * def show_table():

num = int(entry.get())

str1=' Table of ' + str(num) + '\n----------------- \n'

for i in range(1,11):

str1 = str1 + " " + str(num) + " x " + str(i) + " = " + str(num*i) + "\n"

output_label.configure(text = str1, justify=LEFT)

main_window = Tk() main_window.title("Multiplication Table")

message_label = Label(text= ' Enter a number to \n display its Table ' , font=( ' Verdana ' , 12))

output_label = Label(font=( ' Verdana ' , 12)) entry = Entry(font=( ' Verdana ' , 12), width=6)

calc_button = Button(text= ' Show Multiplication Table ' , font=( ' Verdana ', 12), command=show_table)

message_label.grid(row=0, column=0,padx=10, pady=10) entry.grid(row=0, column=1,padx=10, pady=10, ipady=10) calc_button.grid(row=0, column=2,padx=10, pady=10) output_label.grid(row=1, column=0, columnspan=3,padx=10, pady=10) mainloop()


Output :

 

Slip 19 B) Define a class named Shape and its subclass(Square/ Circle). The subclass has an init function which takes an argument (Lenght/redious). Both classes should have methods to calculate area and volume of a given shape.

Answer :

 

class Shape:

                pass

 

class Square(Shape):

                def __init__(self,l2):

                                self.l=l2

                def SArea(self):

                                a=self.l * self.l

                                print("Area of Square:", a)

                def SPerimeter(self):

                                p=4 * self.l

                                print("Perimeter of Square:",p)

class Circle(Shape):

                def __init__(self,r2):

                                self.r=r2

                def CArea(self):

                                a=3.14 * self.r * self.r

                                print("Area of Circle:", a)

                def SCircumference(self):

                                c=2 * 3.14 * self.r

                                print("Circumference of Circle:",c)

#main body

l1=int(input("Enter Length of Square: "))

obj=Square(l1)

obj.SArea()

obj.SPerimeter()

 

r1=int(input("Enter Radius of Circle: "))

obj=Circle(r1)

obj.CArea()

obj.SCircumference()

Output :

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

No comments:

Powered by Blogger.