Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168749
Image: ubuntu2004
a=5 a
5
2==2
True
2>3
False
2**3
8
2^3
8
5/2
5/2
5//2
2
18%5
3
012
10
09
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_13.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("MDk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module> File "/tmp/tmp63EMlZ/___code___.py", line 2 _sage_const_09 = Integer(09) ^ SyntaxError: invalid token
sin?

File: /usr/local/sage2/local/lib/python2.6/site-packages/sage/functions/trig.py

Type: <class ‘sage.functions.trig.Function_sin’>

Definition: sin(*args, coerce=True, hold=False, dont_call_method_on_arg=False)

Docstring:

The sine function.

EXAMPLES:

sage: sin(0)
0
sage: sin(x).subs(x==0)
0
sage: sin(2).n(100)
0.90929742682568169539601986591
sage: loads(dumps(sin))
sin
def is_even(n): return n%2==0 is_even(2)
True
is_even(123)
False
def is_divisible_by(number,divisor=2): return number%divisor==0 is_divisible_by(123,5)
False
is_divisible_by(123)
False
def myfunction(x): if x<0: return -1 elif x==0: return 0 else: return 1 myfunction(-2)
-1
myfunction(0)
0
myfunction(3)
1
money=10000 years=0 while money<20000: years=years+1 money=money*1.069 years
11
money
20833.1411965483
n=10;ans=1; for each in range(1,n+1): ans=ans*each ans
3628800
for eachitem in['name:vincent','age=30','job:teacher']: print eachitem
name:vincent age=30 job:teacher
fibonacci?

File: /usr/local/sage2/local/lib/python2.6/site-packages/sage/combinat/combinat.py

Type: <type ‘function’>

Definition: fibonacci(n, algorithm=’pari’)

Docstring:

Returns the n-th Fibonacci number. The Fibonacci sequence F_n is defined by the initial conditions F_1=F_2=1 and the recurrence relation F_{n+2} = F_{n+1} + F_n. For negative n we define F_n = (-1)^{n+1}F_{-n}, which is consistent with the recurrence relation.

INPUT:

  • algorithm - string:
  • "pari" - (default) - use the PARI C library’s fibo function.
  • "gap" - use GAP’s Fibonacci function

Note

PARI is tens to hundreds of times faster than GAP here; moreover, PARI works for every large input whereas GAP doesn’t.

EXAMPLES:

sage: fibonacci(10)
55
sage: fibonacci(10, algorithm='gap')
55
sage: fibonacci(-100)
-354224848179261915075
sage: fibonacci(100)
354224848179261915075
sage: fibonacci(0)
0
sage: fibonacci(1/2)
...
TypeError: no conversion of this rational to integer
money=10000;years=0 while money<20000: years=years+1 money=money*1.0069
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_2.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("bW9uZXk9MTAwMDA7eWVhcnM9MAp3aGlsZSBtb25leTwyMDAwMDoKICAgIHllYXJzPXllYXJzKzEKIG1vbmV5PW1vbmV5KjEuMDA2OQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module> File "/tmp/tmptR2klD/___code___.py", line 6 money=money*_sage_const_1p0069 ^ IndentationError: unindent does not match any outer indentation level
x=0;x+=1;x
1
x=2;x**=2;x
4
x=[123,'xyz'];x+=[011];x
[123, 'xyz', 9]
x=y=z=123 x
123
y
123
z
123
x,y,z=1,2,3 x
1
y
2
z
3
x=666;y=888 x,y=y,x x
888
y
666