# Revision history [back]

### 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.

 2 retagged slelievre 14964 ●16 ●138 ●297 http://carva.org/samue...

### 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.