Advertisement
PhilHole

The Biker and the Fly

Oct 9th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  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.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement