> i also replaced the infixtopostfix to the problem:
>
> ("5 * 3 ^ (4 - 2)”))
>
> here is the error I am getting :
>
> Traceback (most recent call last):
>   File "/Users/stephaniequiles/Downloads/Listings/listing_3_7.py", line 53, 
> in <module>
>     print(infixToPostfix("5 * 3 ^ (4 - 2)"))
>   File "/Users/stephaniequiles/Downloads/Listings/listing_3_7.py", line 45, 
> in infixToPostfix
>     (prec[opStack.peek()] >= prec[token]):
> KeyError: '(4'
>

Ok.  The immediate problem you are seeing here actually has nothing to do with
exponentiation, but with a lower-level issue.


Answering the following two questions should help you figure out
what's going on.

Given the string:

    "5 * 3 ^ (4 - 2)"

1.  What do you expect the list of tokens to be?  Say concretely what
you expect it to be.

2.  What does your program think the list of tokens is?
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to