I apologize if I didn't explain this well enough but I want to know how I could use my console in my app to take an input like "add 5 4" so it would actually add 5+4 instead of just printing it out. I really just need a function that could take the string "add 5 4" and recognize i started with the word add.
If you want to make a fully-fledged interpreter, I would say learn pyParsing .
Otherwise,
def parse(string):
words = string.rsplit()
if words[0] == "add":
print int(word[1]) + int(word[2])
parse(raw_input());
Notice that I'm doing absolutely no error checking, you should have that in your app.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.