Re: [Tutor] calculator will not multiply

2009-01-18 Thread David
Marc Tompkins wrote: It works for me under Windows XP, so I suspect that the hints you've received about * being expanded by your shell are correct. However, I had an idea - rather than requiring your user to put quotes around the "*", why not do this: elif sys.argv[2] in ["*","x","X"]:

Re: [Tutor] calculator will not multiply

2009-01-18 Thread Marc Tompkins
On Sun, Jan 18, 2009 at 7:37 AM, David wrote: > Everything else works + - / but not * > why? > thanks > -david > > > #!/usr/bin/python > from __future__ import division > import sys > > > def add(x, y): >return x + y > def sub(x, y): >return x - y > def dev(x, y): >return x / y > def

Re: [Tutor] calculator will not multiply

2009-01-18 Thread Kent Johnson
On Sun, Jan 18, 2009 at 10:37 AM, David wrote: > Everything else works + - / but not * > why? > compute(sys.argv[1], sys.argv[2], sys.argv[3]) Because * is a special character to your shell. Probably your shell is expanding the * to a list of files. Try printing sys.argv from within your program

Re: [Tutor] calculator will not multiply

2009-01-18 Thread David
jadrifter wrote: It worked fine for me. Don't forget to put quotes around the * sign or the shell will substitute. so: ./calc.py 2 '*' 9 or: ./calc.py 2 "*" 9 or: ./calc.py 2 \* 9 but not: ./calc.py 2 * 9 John Purser Thanks Kent and jadrifter, that explains that! Also thanks for the tips

Re: [Tutor] calculator will not multiply

2009-01-18 Thread jadrifter
On Sun, 2009-01-18 at 10:37 -0500, David wrote: > Everything else works + - / but not * > why? > thanks > -david > > > #!/usr/bin/python > from __future__ import division > import sys > > > def add(x, y): > return x + y > def sub(x, y): > return x - y > def dev(x, y): > return x

Re: [Tutor] calculator will not multiply

2009-01-18 Thread Andre Engels
There's an editing error in my previous message. The corrected function should not be: def compute(arg1, arg2, arg3): if sys.arg2 == "+": total = add(int(sys.arg1), int(sys.arg3)) print total elif sys.arg2 == "-": total = sub(int(sys.arg1), int(sys.arg3)) print t

Re: [Tutor] calculator will not multiply

2009-01-18 Thread Andre Engels
On Sun, Jan 18, 2009 at 4:37 PM, David wrote: > Everything else works + - / but not * > why? > thanks > -david It works for me. However, I do have another issue with your code: > def compute(arg1, arg2, arg3): >if sys.argv[2] == "+": >total = add(int(sys.argv[1]), int(sys.argv[3]))

[Tutor] calculator will not multiply

2009-01-18 Thread David
Everything else works + - / but not * why? thanks -david #!/usr/bin/python from __future__ import division import sys def add(x, y): return x + y def sub(x, y): return x - y def dev(x, y): return x / y def mul(x, y): return x * y def compute(arg1, arg2, arg3): if sys.argv[2