Question

Can someone help me with the problem below? Parentheses Matching Program: Implement and test a Python...

Can someone help me with the problem below?

Parentheses Matching Program:

Implement and test a Python program that determines if parentheses in an entered line of code form matching pairs. Note: pairs of parentheses may be nested

0 0
Add a comment Improve this question Transcribed image text
Answer #1

str1=input("please enter a set of paranthesis\n")#asks user to enter sting of ( )

count=0#intitalize count and count1 to 0

count1=0

for i in range(len(str1)):#loop runs from till len(str1)

    if i==0:#if the first character in str1 is ) then it is not a proper matching of paranthesis

        if str1[i]==')':

            print("No matching pairs found")# so display this message

            break# break the loop

        else:

            count=count+1#else it must be '(' then increment count

    else:

        if str1[i]=='(':#if i!=0 then check for character if it is '(' then increment count

            count=count+1

        else:

            count1=count1+1#else increment count1

if(count!=0 and count1!=0):#f count and count1 is not eqaul to zero

    if(count1==count):#if count==count1

        print("Matching pairs found")#print matching

    else:

        print("Not a matching pair")#else not mathing

else:

    print("you have not entered any string")

Add a comment
Know the answer?
Add Answer to:
Can someone help me with the problem below? Parentheses Matching Program: Implement and test a Python...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem Implement (in C) an algorithm that uses a stack to check if a parentheses sequence is balanced. Note that a par...

    Problem Implement (in C) an algorithm that uses a stack to check if a parentheses sequence is balanced. Note that a parentheses sequence is balanced if it is of the form (S) or of the form (SS), where S is any balanced parentheses sequence. See the courseware for more information on balanced parentheses sequences. Implement a stack using an array Test your program on three different kinds of inputs: 1. String is unbalanced in the sense that there are more...

  • Help me write a python code. Write a program that asks the user for the name...

    Help me write a python code. Write a program that asks the user for the name of a text file, then reads each line of the text file and prints it on the screen, making every other line "title case." For example, suppose the following text is saved in my_file.txt: While I nodded, nearly napping Suddenly there came a tapping As of someone gently rapping, Rapping at my chamber door. When run, the program looks like this: Enter filename: While...

  • IMPLEMENT IN C++ Implement a symbol balance checker function for the Pascal programming language. Pascal allows...

    IMPLEMENT IN C++ Implement a symbol balance checker function for the Pascal programming language. Pascal allows for the following pairs: {}, (), [], begin end . All programs will begin with the word "begin" and end with the word "end". Your function should receive an ifstream object which is already open and will return true, all of the symbols match, or false, they do not. You do not have to worry about comments in the program but you do have...

  • Can someone help me with this problem. We're using microsoft visual studios and its from my...

    Can someone help me with this problem. We're using microsoft visual studios and its from my assembly code language class. we're using this template in class from the lecture slides Write a program and verify it using visual studio that does the following: Use type, lengthof, and size to make your program more independent of the data type. 3) Write a program that first reads the message entered by the user and stores it in Myname. Then it prints the...

  • Can someone please help me with this problem? We are using CodeWarrior to write this program...

    Can someone please help me with this problem? We are using CodeWarrior to write this program in assembly language. The array sample contains eight 8-bit signed binary numbers (integers) as shown below. Write a program which stores the negative numbers in the array nelements, computes the sum of the positive numbens to be stored in the variable psum and stores the number of the positive numbers in the variable pnumber. Note that a zero is ther positive nor negative. Your...

  • hii, can you please help me to implement a program in c# that creates a form...

    hii, can you please help me to implement a program in c# that creates a form and make automatic schedule for any store. in visual studio 2019, create a schedule maker . how to read a file in window form application

  • CAN SOMEONE PLEASE HELP ME WRITE THIS CODE IN C++, PLEASE HAVE COMMENTS IN THE CODE...

    CAN SOMEONE PLEASE HELP ME WRITE THIS CODE IN C++, PLEASE HAVE COMMENTS IN THE CODE IF POSSIBLE!! General Description: Write a program that allows the user to enter data on their friends list. The list holds a maximum of 10 friends, but may have fewer. Each friend has a name, phone number, and email address. The program first asks the user to enter the number of friends (1-10). You are not required to validate the entry, but you may...

  • Can someone please help implement code for the following Python example! 44 This represents an entire...

    Can someone please help implement code for the following Python example! 44 This represents an entire grouping of Grade values as a list (named grades). as We can then dig through this list for interesting things and calculations by 46 calling the methods we're going to implement, 47 aB class G Define the GradeBook class, se def init (self): GradeBook constructor, create the only instance variable, S1 a list named grades, and initialize it to an empty list, This means...

  • Can someone help me with this problem?

    Can someone help me with this problem?

  • Can someone help me solve this problem please A combinational circuit converts an Excess-3 input (ABCD)...

    Can someone help me solve this problem please A combinational circuit converts an Excess-3 input (ABCD) into a binary coded decimal output (WXYZ) All invalid combinations are dont cares. Implement the X output using the two level form NOR-OR, and the Y output using AND-NOR. DO NOT IMPLEMENT (W OR Z)

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT