Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

sidd607 Group Title

how do you convert a string such as (2+3)*4+(4+5) to a list such as [[2,"+",3],"*",4,"+",[4,"+",5]] and evaluate the value of the expression??

  • one year ago
  • one year ago

  • This Question is Open
  1. e.mccormick Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    You would need to examine the string using some sort of a loop and find all the parenthesis first. This would allow you to build the order of operations into your evaluation system. In fact, working with the order of operations would be the real key. That would let you place things in the list in the order they need to be evaluated to get an answer. Also, your evaluation routine would need to loop or recurs based on if it finds a list within the list.

    • one year ago
  2. A.Avinash_Goutham Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    use a stack..

    • one year ago
  3. e.mccormick Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @A.Avinash_Goutham He posted in the MIT 6.189 area, which is an Intro to Python class. In Python, the list can be used as a stack. With append() and pop() it becomes a LIFO data structure.

    • one year ago
  4. sidd607 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    i got the logic. But the problem is i am not being able to write the proper code.

    • one year ago
  5. e.mccormick Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Well, what did you come up with?

    • one year ago
  6. droopy4096 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @sidd607 , while not my solution, here's what google brings up - http://stackoverflow.com/questions/2371436/evaluating-a-mathematical-expression-in-a-string in other words - there is no simple solution to this as you have to parse numerical strings that can get pretty hairy...

    • one year ago
  7. goformit100 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    A warm Welcome to OpenStudy. I can help guide you through this useful site. You can ask your questions to me or you can message me. Please use the chat for off topic questions. Remember to give the person who helped you a medal by clicking on "Best Answer". We follow a code of conduct, ( http://openstudy.com/code-of-conduct ). Please take a moment to read it.q

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.