How do you set up a stack?

Tyler Eaves tyler at tylereaves.com
Tue May 8 22:39:14 EDT 2001


On Wed, 09 May 2001 02:01:35 GMT, the_2nd_coming
<jpetzold at twmi.rr.com> wrote:


try this code:

f=raw_input('>')
print eval(f)


>hello,
>I am a python/programming newbie (Python is my first language),
>and I am writing a program that will be able to take a mathematical 
>function, that, as of right now, is restricted to Multiply and Divide with 
>one operator, (2/4 or 3*7). I want to be able for the end-user to be able 
>to type the function at the python prompt and to have the program create a 
>list of the characters in the list, I am using raw_input and I think I need 
>to implement a stack  in order to pass each character to the list as I pop 
>them off the stack. this is good and all, however, I do not know how to 
>implement this.
>
>this is what the layout is at this point:
>
>
>
>
>        function = raw_input("put your function hear")
>                        .
>                        . #this is where the stack will be implemented and the  
>                        . # charactors will be placed in the list.
>        operator = function_list[1] # item 1 will be the position of the operator
>                                #in the list after any whitespace is striped.
>        
>        if operator == "*": #the operator is the astrik
>                multiplication(function_list[0], Function_list[2])
>        
>        else:
>                Division(Function_list[0], Function_list[2])
>
>        # the rest of the program
>
>so, how do I implement a stack, and, is there any other way I could 
>acomplish this task?
>
>thank-you in advance
>
>Jeremy Petzold




More information about the Python-list mailing list