calculator

“Unorderable types: int() < str()”

对着背影说爱祢 提交于 2019-11-26 03:59:13
问题 I\'m trying to make a retirement calculator right now on Python. There\'s nothing wrong with the syntax but when I run the following program: def main(): print(\"Let me Retire Financial Calculator\") deposit = input(\"Please input annual deposit in dollars: $\") rate = input (\"Please input annual rate in percentage: %\") time = input(\"How many years until retirement?\") x = 0 value = 0 while (x < time): x = x + 1 value = (value * rate) + deposit print(\"The value of your account after\"

Smart design of a math parser?

ⅰ亾dé卋堺 提交于 2019-11-26 02:18:08
问题 What is the smartest way to design a math parser? What I mean is a function that takes a math string (like: \"2 + 3 / 2 + (2 * 5)\") and returns the calculated value? I did write one in VB6 ages ago but it ended up being way to bloated and not very portable (or smart for that matter...). General ideas, psuedo code or real code is appreciated. 回答1: A pretty good approach would involve two steps. The first step involves converting the expression from infix to postfix (e.g. via Dijkstra's