问题描述:

I want to create a table with a specific array increments corresponding to that specific time. for example:

`n sec`

100 0.2

200 0.4

etc..

Y is number of tries of specific array, n is the array size, increment is specific increment

`if sortfunction==1:`

i=0

while i<y:

dt=0

for i in range(n):

i=i+increment

dt+=sort_timehelp(x,quick_sort)

output="%d %f\n" %(i,dt)

print output

for example if i put N as 1000 and increment 100, then it would look something like an above table.

right now i get:

`n sec`

100 0.001

101 0.0012

102 0.0014

etc it goes by 1 not by the increment size

EDIT:

I got another question: why this does this while loop doesn't go more times?

`i=0`

while i<y:

i=i+1

dt=0

for i in xrange(increment, n+increment, increment):

dt+=sort_timehelp(x, quick_sort)

output="%d %f\n" %(i,dt)

print output

i is the number of array tests.

Why it doesn't go for example 2 times

Edit: Never mind I used for loop instead.

I have a last question.

What if I have a lot of those kinds of if statements only the difference is a sortfunction, then how can i save it all of that stuff to a file, since when I tried it will only save a last printed statement

`#`

saving=input("You want to save data ? type 0 to continue or 1 to save " )

if saving == 0:

continue

if saving == 1:

ask=raw_input("Type the name file: ")

fileout=open(ask+".csv","a")

fileout.write(output)

fileout.close()

the indentation of "saving" is the same as if sortfunction

The range(n) function returns a list [0,1,2,...], which the for loop then iterates over. So when i is 0 and your do `i=i+increment`

, your value of i (100) gets thrown away, and replaced with the next element of the list - i.e. 1.

You can instead try `for i in range(increment,n+increment,increment)`

, and then delete the first line inside your for block. The range function itself will add `increment`

every iteration of the loop - i.e. i will be 100,200,300,...,1000

```
for i in xrange(increment, (n+1)*increment, increment):
dt+=sort_timehelp(x,quick_sort)
output="%d %f\n" %(i,dt)
print output
```