Advertisement
Guest User

Position-Time Graph

a guest
Sep 21st, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. ## Position-Time Graph Calculation.
  4. ## 09/21/19, Fort Lauderdale High School.
  5. ## Arsen Petrosian.
  6.  
  7. def main():
  8.     # Input.
  9.     correct_input = False
  10.     while not correct_input:
  11.         try:
  12.             velocity_init = float(input("Enter the initial velocity in m/s: "))
  13.             time_interval = int(input("Enter your time interval in seconds: "))
  14.             acceleration = float(input("Enter the acceleration in m/s^2: "))
  15.  
  16.             # When we get no type errors, we consider the input data correct.
  17.             correct_input = True
  18.         except ValueError:
  19.             print("\nYou just entered something wrong. Try again, please.\n")
  20.    
  21.     # Output.
  22.     print("TIME: \t POSITION:")
  23.     for time in range(time_interval):
  24.         position = get_position(velocity_init, acceleration, time)
  25.         print(f"{time} s \t {position} m")
  26.  
  27. def get_position(velocity_init, acceleration, time):
  28.     """
  29.    Calculates the position using X = ViT + (1/2)A(T)^2.
  30.    """
  31.  
  32.     return ((velocity_init * time) + ((0.5 * acceleration) * (time ** 2)))
  33.  
  34. if __name__ == "__main__":
  35.     try:
  36.         main()
  37.     except KeyboardInterrupt:
  38.         print("\nBye.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement