ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 27 Mar 2016 11:28:01 +0200range and division : unexpected behaviorhttps://ask.sagemath.org/question/32891/range-and-division-unexpected-behavior/Consider the following snippet :
N=5
# code 1
for n in range(N,N+1):
for k in range(0,n):
print k/n
print '-'*10
# code 2
n=N
for k in range(0,n):
print k/n
I was expecting code 1 and code 2 to print the same output. This is not the case :
0
0
0
0
0
----------
0
1/5
2/5
3/5
4/5
In the first case, `k/n` is Python-evaluated as an integer division, in the second case, `k/n` is Sage-evaluated as a fraction. Can someone elaborate please ?
I only notice that substituting `srange(N,N+1)` to `range(N,N+1)` fixes the problem.
candideSun, 27 Mar 2016 11:28:01 +0200https://ask.sagemath.org/question/32891/