On Apr 20, 2011, at 21:34 , tvn wrote:
> I wrote this small function
>
> def test(p):
> """
>>>> var('x')
> x
>>>> test(1/2*x)
> 1/2*x
> """
> print p
>
> and run doctest on it and receives the following result
>
> File "test.py", line 7, in test.test
> Failed example:
> test(1/2*x)
> Expected:
> 1/2*x
> Got:
> 0 <========== Why did it get 0 here ?
> **********************************************************************
> 1 items had failures:
> 1 of 2 in test.test
> ***Test Failed*** 1 failures.
> TestResults(failed=1, attempted=2)
>
>
>
> what's the reason and how to get around it ? Thanks
You are using a ".py" file, so Sage treats it as python (not Sage) code. It
doesn't get preparsed using Sage's rules. In particular, "a/b" is the integer
quotient, not the rational numnber.
You could try something like "Integer(1)/Integer(2)" to get "1/2" as a (Sage)
rational.
HTH
Justin
--
Justin C. Walker, Curmudgeon at Large
Director
Institute for the Enhancement of the Director's income
-----------
--
They said it couldn't be done, but sometimes,
it doesn't work out that way.
- Casey Stengel
--
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org