Re: [Tutor] catching errors in calculator script

2007-09-18 Thread Alan Gauld
"Christopher Spears" <[EMAIL PROTECTED]> wrote >I wrote a simple calculator script: > > #!/usr/bin/python env > > def calculator(n1, operator, n2): >f1 = float(n1) >f2 = float(n2) You probably shouldn't do this since it forces all your results to be floats even if the two arguments a

[Tutor] catching errors in calculator script

2007-09-17 Thread Christopher Spears
I wrote a simple calculator script: #!/usr/bin/python env def calculator(n1, operator, n2): f1 = float(n1) f2 = float(n2) if operator == '+': return f1 + f2 elif operator == '-': return f1 - f2 elif operator == '*': return f1 * f2 elif operator == '