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

   Write a Python program

Slip 10 A) Write Python GUI program to display an alert message when a button is pressed.

Answer :


from tkinter

import * import tkinter.messagebox root = tkinter.Tk()

root.title("When you press a button the message will pop up") root.geometry('500x300')

 

def onClick():

 

tkinter.messagebox.showinfo("Welcome to TYBBACA Student", "Hi I'm Ramesh")

button = Button(root, text="Click Me", command=onClick, height=5, width=10)

button.pack(side='bottom')

root.mainloop()

Output :

 

Slip 10 B) Write a Python class to find validity of a string of parentheses, '(', ')', '{', '}', '[' ']’. These brackets must be close in the correct order. for example "()" and "()[]{}" are valid but "[)", "({[)]" and "{{{" are invalid.

Answer :

 

s="{()[}("

lst=[]

if len(s) % 2 != 0:

    print("Invalid Sequence")

else:

    for b in s:

        if b=="(" or b=="{" or b=="[":

            lst.append(b)

        elif b==")" or b=="}" or b=="]":

            cnt=len(lst)-1

            if b==")":

                if lst[cnt]=="(":

                    lst.pop()

                else:

                    print("Invalid Sequence")

                    break

            if b=="}":

                if lst[cnt]=="{":

                    lst.pop()

                else:

                    print("Invalid Sequence")

                    break

            if b=="]":

                if lst[cnt]=="[":

                    lst.pop()

                else:

                    print("Invalid Sequence")

                    break

        if len(lst)==0:

            print("valid Sequence")

Output :

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

No comments:

Powered by Blogger.