Oh whoa.
I had no idea about eval! Very cool. It makes me almost embarrassed that I've been writing this simple calculator (only handles the basic operators and has no error handling yet) that by now has evolved into using multiple 'for statements' and recursion. I think I'm reinventing the wheel (poorly).
All of that being said, since my goal is to teach myself, my little pet project has been quite successful. I'm learning...
User Profile
Collapse
-
EDIT because I figured out a bit more.
So I was misunderstandin g what the "for i in blaba" was actually returning. I get that now, it's already returning the value inside of the list. I can change my code to partially accomodate for that, but what I really wanted to do -- the spirit of what I was trying to do -- was to run the function passing in a different value each time by changing the index of the list by one until the...Leave a comment:
-
"list indices must be integers, not str"
I'm writing a calculator that takes simple input. This is the code so far.
...Code:def getlist(rawstring): stringclip = rawstring.replace(" ", "") oplist = {'+':' + ','-':' - ','*':' * ','/':' / ','(':' ( ',')':' ) ','^':' ^ '} ''' This replacement implementation came from http://gomputor.wordpress.com/ ''' for i, j in oplist.iteritems(): stringclip = stringclip.replace(i, -
The .replace thing works like magic.
I'll tip my hand a bit: I'm trying to build a calculator that takes text input. This first step is just to take the input and create a list of the values and operators in order so that I can work with them later.
After you mentioned the .replace idea I found a blog entry about how to do multiple replacements so that I can do this for multiple operators. My code looks like this:
...Leave a comment:
-
Thanks for the help! I'll hack away a bit and post the results here.Leave a comment:
-
Trouble adding blank space to a list
I'm a python newbie (in fact I'm a programming newbie). I'm teaching myself python for the fun of it by reading several online tutorials and then creating useless little scripts.
For the past longer-than-I-would-care-to-admit I have been struggling to get this little bit of code to work:
...Code:for i in stringexp: if 'stringexp[i]' == '+': stringexp.insert[i, " "] stringexp.insert[(i
No activity results to display
Show More
Leave a comment: