这是我到目前为止所拥有的:
#random numbers from 0 to 1
total=0 #use a empty 'total' to create the values in second column
for i in range (10):
x=random.random()
total=total+x
print(x,total)
average=(total/10)
print('Average:',average)
这将产生2列;第一个具有10个不同的随机数,第二个具有与前一个随机数相加的数字。它以平均值结尾。
我现在需要添加另一个for循环才能找到这些平均值中的10个。
答案 0 :(得分:1)
您的意思是这样的吗?
import random
for n in range(10):
total = 0
for i in range(10):
x = random.random()
total = total + x
print(x, total)
average = (total / 10)
print('Average:', average)