_s8

Untitled

_s8
Oct 22nd, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.64 KB | None | 0 0
  1. import time
  2.  
  3. """
  4. Very, VERY simple sim showing results of running x miles or for x times.
  5. (assuming that the runner has a CONSTANT mph, and doesn't slow down or speed up.)
  6. """
  7.  
  8. class runner_(object):
  9.     def __init__(self, name, mph):
  10.         self.name = name
  11.         self.mph = mph
  12.  
  13. def run_simulation(runners, miles, stride=1):
  14.     times = {}
  15.     for x in range(1, miles+1, stride):
  16.         time.sleep(1)
  17.         for runner in runners:
  18.             dv_by = runner.mph/x
  19.             times[runner] = {x:60/dv_by}
  20.             for data in times[runner]:
  21.                 print("{}: {} miles ({} minutes)".format(runner.name, str(round(data, 2)), str(round(times[runner][data], 2))))
  22.     print("Finishing times: \n")
  23.     for runner in times:
  24.         time.sleep(1.25)
  25.         for mile in times[runner]:
  26.             print("{}: {} miles in {} minutes".format(runner.name, str(round(mile, 2)), str(round(times[runner][mile], 2))))
  27.  
  28. def run_time(runners, minutes, stride=1, wait=0):
  29.     times = {}
  30.     for runner in runners:
  31.         times[runner.name] = 0
  32.     for x in range(1, minutes+1, stride):
  33.         time.sleep(wait)
  34.         for runner in runners:
  35.             runner_mpm = round(runner.mph/60, 2)
  36.             times[runner.name] += runner_mpm
  37.         for runner_times in times:
  38.             print("{}: {} miles ({} minutes)".format(runner_times, round(times[runner_times], 2), x))
  39.     print("Results: \n")
  40.     for time__ in times:
  41.         print("{} ran {} miles in {} minutes.".format(time__, round(times[time__], 2), minutes))
  42.  
  43. # Sample runners:
  44. Mikey = runner_('Mikey', 23)
  45. John = runner_('John', 12)
  46. run_time([Mikey, John], 100, 1)
Advertisement
Add Comment
Please, Sign In to add comment