SHARE
TWEET

The Biker and the Fly

PhilHole Oct 9th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. bikerSpeed = 15
  2. flySpeed = 40
  3. bikerPosition = 0
  4. flyPosition = 0
  5.  
  6. flyTotalDistanceTraveled = 0
  7.  
  8. flyIsTravelingTowardsHouse = True
  9.  
  10. while(bikerPosition < 5):
  11.     bikerPosition += 1/3600 * bikerSpeed
  12.  
  13.     if(flyIsTravelingTowardsHouse):
  14.         flyPosition += 1/3600 * flySpeed
  15.         if(round(flyPosition, 1) == 5):
  16.             print("Biker: " + str(round(bikerPosition, 1)) + " Fly: " + str(round(flyPosition, 1)))
  17.             flyIsTravelingTowardsHouse = False
  18.     else:
  19.         flyPosition -= 1/3600 * flySpeed
  20.         if(round(flyPosition, 1) == round(bikerPosition, 1)):
  21.             print("Biker: " + str(round(bikerPosition, 1)) + " Fly: " + str(round(flyPosition, 1)))
  22.             flyIsTravelingTowardsHouse = True
  23.  
  24.     flyTotalDistanceTraveled += 1/3600 * flySpeed
  25.  
  26.     # print("Biker: " + str(round(bikerPosition, 1)) + " Fly: " + str(round(flyPosition, 1)))
  27.  
  28. print("The Fly traveled " + str(round(flyTotalDistanceTraveled, 1)) + " kilometers.")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top