SHARE
TWEET

Untitled

a guest May 25th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Programming I
  2.  
  3. ###########################
  4. #     Side Quest 5.1      #
  5. #   Driverless Vehicle    #
  6. ###########################
  7.  
  8. #Background
  9. #==========
  10. #Tom decided to start his own company to create a driverless vehicle. He is programming
  11. #the collision avoidance system of the vehicle. The vehicle uses sonar sensor to measure
  12. #distance between objects. It measures distance by sending out a sound wave and listening
  13. #for that sound wave to bounce back. By recording the round trip time (seconds) from the
  14. #sound wave being generated, to the sound wave bouncing back, it is possible to calculate
  15. #the distance between the vehicle and the object.
  16.  
  17. #Given that sound travels through the air at 344 m/s, write a Python program that will
  18. #find the closest object to the vehicle and return a list containing the index and the distance of the object.
  19. #1. Prompt the user to enter minimum 5 round trip times, each value separated by comma
  20. #       (e.g. user should input in the format of 0.5, 2.1, 0.3, 1.8, 2.3)
  21. #2. If the user enters lesser than 5 timings, the program should prompt and error and return a list with the value [-1,-1]
  22. #3. Calculate the distance and find the closest object.
  23. #4. Print and return the index of the object in the user input, and the distance of this object.
  24.  
  25.  
  26.  
  27.  
  28. #Important Notes
  29. #===============
  30. #1) Comment out ALL input prompts before submitting.
  31. #2) You MUST use the following variables
  32. #   - roundTrips
  33. #   - closestObject
  34.  
  35.  
  36.  
  37. #START CODING FROM HERE
  38. #======================
  39.  
  40. #Prompt user to enter a minimum of 5 round trip times separated with commas
  41. roundTrips = str(input("Enter the round trip times, seperating with commas ( more than 4 ) : "))
  42.  
  43.  
  44. #Check closest object
  45. def closest_object(roundTrips):
  46.     #Perform the parsing of roundTrips input here
  47.  
  48.    
  49.    
  50.     closestObject = []
  51.  
  52.     print('The closest object is',closestObject) #Modify to display the closest object
  53.    
  54.     return closestObject#Do not remove this line
  55.  
  56.    
  57. #Do not remove the next line
  58. closest_object(roundTrips)
  59.  
  60.  
  61. #input 0.5,2.1,0.3,1.8,2.3  output [2, 51.6]
  62. #input 0.1,2.0,1.6,0.05     output [-1,-1]
  63. #input 0.1,2.0,1.6,.5,1     output [0, 17.2]
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