```
import random
import math
import numpy as np
import xlwings as xw
#***The average distance (dis)** after n times of simulation picking t times per person
print("How many products do you have?>> ")
q = int(input())
print("What number(n) would you like to simulate?>> ")
n = int(input())
arr = []
def sort_num(x):
return x
A1 = (1,3,5,7,9,11,13,15,17,19)
B1 = (5,7,9,11,13,15,17,19,21,23,7,9,11,13,15,17,19,21,23,25,9,11,13,15,17,19,21,23,25,27)
C1 = (11,13,15,17,19,21,23,25,27,29,13,15,17,19,21,23,25,27,29,31,15,17,19,21,23,25,27,29,31,33,17,19,21,23,25,27,29,31,33,35,19,21,23,25,27,29,31,33,35,37)
result1 = 0
for i in range(n):
for i in range(int(q)):
x = int(random.randrange(1, 11))
if x<=7 :
ax = int(random.choice(A1))
result1 = ax
if x>7 and x<=9:
ax = int(random.choice(B1))
result1 = ax
if x>9 and x<=10:
ax = int(random.choice(C1))
result1 = ax
arr.append(result1)
print(sorted(arr))
```

I made the code like this, but I don't know how to proceed with this.

python

2022-09-20 14:32

```
arr = sorted(arr)
diffsum = 0
for x, x_next in zip(arr[:-1], arr[1:]):
diff_sum += x_next-x
```

You can do this, but if you calculate the equation, it's erased one after another, and eventually x_q - x_1

```
arr = sorted(arr)
diffsum = arr[-1] - arr[0]
```

2022-09-20 14:32

Popular Tags

Popular Questions

13 If parameter X determines the return value Y, which function name would be the most appropriate?

11 I have a question about the pointer! *z = ~(hap & 0xFF); What does ~ mean in?

8 ipynb code content search tool recommendation

9 Find the intersection of two lists

13 I want to apply all the files in the folder as a for statement.

© 2022 pinfo. All rights reserved.