Home:ALL Converter>How to make this simulation of which year a Solarflare hits the Earth faster?

How to make this simulation of which year a Solarflare hits the Earth faster?

Ask Time:2022-06-29T00:59:16         Author:Yohenis Cruz Salazar

Json Formatter

I wrote this code and try to learn a bit more how to code more efficiently and increase performance.

import random

def CalcAverageSolarFlareEvent(EventList):
    return sum(EventList) / len(EventList)

percentage_solar_flare = 12
decade_counting = 0
Event = []
CurrentYear = 2022

for Simulations in range(1, 999999):
    while True:
        if random.randint(1, 100) != percentage_solar_flare:
            decade_counting += 1
        else:
            Event.append(decade_counting)
            decade_counting = 0
            break

print("In the Year "+str(int(CalcAverageSolarFlareEvent(Event))*10+CurrentYear) +
      " we got a Solarflare")

I tried to calculate the decade_counting and adding current year at the end, to give more ram.

Author:Yohenis Cruz Salazar,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/72790519/how-to-make-this-simulation-of-which-year-a-solarflare-hits-the-earth-faster
yy