NOTE: This program has two types of variables. Normal variables are the ones that you are used to using. User variables are variables defined by the user with the store command. The term variable is used in both cases, so it is usually up to you to not get confused which one is intended in each context.
resolve(argument)
with the
following properties:
argument
is assumed to be a stringargument
starts with a letter, then it is assumed
to be the name of a variable. Otherwise, it is assumed to be a number.argument
is a variable that cannot be found in
the dictionary of variables, then resolve
returns
0.0argument
is a variable that can be found in the
dictionary of variables, then resolve
returns the value
of the variableresolve
returns the argument converted into floating point format.string
and math
modules.string.letters
is a string that contains all of the
characters that are considered lettersvariables
: a dictionary for keeping track of user
variablesdoLoop
: a boolean varible set to True for the while
looplast
: the result of the previous operation. Initialize
it to zero.split
to immediately split the
raw_input
into a list for easier processingHere is an example session, with user input in red.
? + 1 2
3.0
? store a
a = 3.0
? + a 5
8.0
? + a a
6.0
? * a a
9.0
? pow a 2
9.0
? store b
b = 9.0
? / b a
3.0
? - b a
6.0
? showall
a = 3.0
b = 9.0
? clear
Variables cleared.
? showall
? + a b
Unknown variable: a
Unknown variable: b
0.0
? + a 1
Unknown variable: a
1.0
? dance
Unknown operation.
? exit