1

I have written a few python script. But this is my first time of seeing expressions like "for _ in range(100000)". Can anyone point me a direction regarding this? I didn't find it from google. What does "_" mean? no parameter is needed, and we can use this merely to say loop for 100000 times?

from numpy import random
random.seed(0)

totals = {20:0, 30:0, 40:0, 50:0, 60:0, 70:0}
purchases = {20:0, 30:0, 40:0, 50:0, 60:0, 70:0}
totalPurchases = 0
for _ in range(100000):
    ageDecade = random.choice([20, 30, 40, 50, 60, 70])
    purchaseProbability = float(ageDecade) / 100.0
    totals[ageDecade] += 1
    if (random.random() < purchaseProbability):
        totalPurchases += 1
        purchases[ageDecade] += 1
Sarah
  • 453
  • 7
  • 16

0 Answers0