On Sun, Jan 18, 2009 at 7:37 AM, David <span dir="ltr">&lt;<a href="mailto:david@abbottdavid.com">david@abbottdavid.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Everything else works + - / but not *<br>
why?<br>
thanks<br>
-david<br>
<br>
<br>
#!/usr/bin/python<br>
from __future__ import division<br>
import sys<br>
<br>
<br>
def add(x, y):<br>
 &nbsp; &nbsp;return x + y<br>
def sub(x, y):<br>
 &nbsp; &nbsp;return x - y<br>
def dev(x, y):<br>
 &nbsp; &nbsp;return x / y<br>
def mul(x, y):<br>
 &nbsp; &nbsp;return x * y<br>
def compute(arg1, arg2, arg3):<br>
 &nbsp; &nbsp;if sys.argv[2] == &quot;+&quot;:<br>
 &nbsp; &nbsp; &nbsp; &nbsp;total = add(int(sys.argv[1]), int(sys.argv[3]))<br>
 &nbsp; &nbsp; &nbsp; &nbsp;print total<br>
 &nbsp; &nbsp;elif sys.argv[2] == &quot;-&quot;:<br>
 &nbsp; &nbsp; &nbsp; &nbsp;total = sub(int(sys.argv[1]), int(sys.argv[3]))<br>
 &nbsp; &nbsp; &nbsp; &nbsp;print total<br>
 &nbsp; &nbsp;elif sys.argv[2] == &quot;/&quot;:<br>
 &nbsp; &nbsp; &nbsp; &nbsp;total = dev(int(sys.argv[1]), int(sys.argv[3]))<br>
 &nbsp; &nbsp; &nbsp; &nbsp;print total<br>
 &nbsp; &nbsp;elif sys.argv[2] == &quot;*&quot;:<br>
 &nbsp; &nbsp; &nbsp; &nbsp;total = mul(int(sys.argv[1]), int(sys.argv[3]))<br>
 &nbsp; &nbsp; &nbsp; &nbsp;print total<br>
 &nbsp; &nbsp;else:<br>
 &nbsp; &nbsp; &nbsp; &nbsp;print &quot;oops&quot;<br>
<br>
compute(sys.argv[1], sys.argv[2], sys.argv[3])<br><font color="#888888">
<br>
</font></blockquote><div><br>It works for me under Windows XP, so I suspect that the hints you&#39;ve received about * being expanded by your shell are correct.&nbsp; However, I had an idea - rather than requiring your user to put quotes around the &quot;*&quot;, why not do this:<br>
<br>&nbsp;&nbsp; elif sys.argv[2] in [&quot;*&quot;,&quot;x&quot;,&quot;X&quot;]:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; total = mul(int(sys.argv[1]), int(sys.argv[3]))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print total<br><br>This could be a problem if you wanted to develop your calculator into a full-fledged scientific calculator, but otherwise...<br>
</div></div><br clear="all"><br>-- <br><a href="http://www.fsrtechnologies.com">www.fsrtechnologies.com</a><br>