所以基本上我需要创建一个标记为 [0,1,2,3,4,5,10,25,100] 的缓冲区列表。然后我需要在 (0.75 和 4.75)+3 之间创建随机数。现在我需要打印类似“Buffer 3 take and average of x seconds”之类的东西。x将是生成的随机数。每个缓冲区必须有自己的随机数
def main():
buffer= [0,1,2,3,4,5,10,25,100]
time= random.uniform(0.75,4.75)+3
sum=0
for i in range (1, 500):
sum = sum + time;
average= sum/1500
for buffer in range(0,1,2,3,4,5,10,25,100):
print("For Buffer",buffer,",the average time is",average,".")
[解决了]
#Lab 1 using python.
Import random #Importing random number generator.
def main():
buffers= [0,1,2,3,4,5,10,25,100]; #Defining the buffers using list.
for buffer in buffers:
sum=0;
for i in range (1, 500): # Create a loop which will create random number and increment 500 times.
time= (random.uniform (0.75,4.75))+3
sum = sum + time
average= sum/500; #Finding the average of each buffers random numbers.
print("For Buffer",buffer,",the average time is",average,"."); #Print the output.