Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- """
- Very, VERY simple sim showing results of running x miles or for x times.
- (assuming that the runner has a CONSTANT mph, and doesn't slow down or speed up.)
- """
- class runner_(object):
- def __init__(self, name, mph):
- self.name = name
- self.mph = mph
- def run_simulation(runners, miles, stride=1):
- times = {}
- for x in range(1, miles+1, stride):
- time.sleep(1)
- for runner in runners:
- dv_by = runner.mph/x
- times[runner] = {x:60/dv_by}
- for data in times[runner]:
- print("{}: {} miles ({} minutes)".format(runner.name, str(round(data, 2)), str(round(times[runner][data], 2))))
- print("Finishing times: \n")
- for runner in times:
- time.sleep(1.25)
- for mile in times[runner]:
- print("{}: {} miles in {} minutes".format(runner.name, str(round(mile, 2)), str(round(times[runner][mile], 2))))
- def run_time(runners, minutes, stride=1, wait=0):
- times = {}
- for runner in runners:
- times[runner.name] = 0
- for x in range(1, minutes+1, stride):
- time.sleep(wait)
- for runner in runners:
- runner_mpm = round(runner.mph/60, 2)
- times[runner.name] += runner_mpm
- for runner_times in times:
- print("{}: {} miles ({} minutes)".format(runner_times, round(times[runner_times], 2), x))
- print("Results: \n")
- for time__ in times:
- print("{} ran {} miles in {} minutes.".format(time__, round(times[time__], 2), minutes))
- # Sample runners:
- Mikey = runner_('Mikey', 23)
- John = runner_('John', 12)
- run_time([Mikey, John], 100, 1)
Advertisement
Add Comment
Please, Sign In to add comment