Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- ## Position-Time Graph Calculation.
- ## 09/21/19, Fort Lauderdale High School.
- ## Arsen Petrosian.
- def main():
- # Input.
- correct_input = False
- while not correct_input:
- try:
- velocity_init = float(input("Enter the initial velocity in m/s: "))
- time_interval = int(input("Enter your time interval in seconds: "))
- acceleration = float(input("Enter the acceleration in m/s^2: "))
- # When we get no type errors, we consider the input data correct.
- correct_input = True
- except ValueError:
- print("\nYou just entered something wrong. Try again, please.\n")
- # Output.
- print("TIME: \t POSITION:")
- for time in range(time_interval):
- position = get_position(velocity_init, acceleration, time)
- print(f"{time} s \t {position} m")
- def get_position(velocity_init, acceleration, time):
- """
- Calculates the position using X = ViT + (1/2)A(T)^2.
- """
- return ((velocity_init * time) + ((0.5 * acceleration) * (time ** 2)))
- if __name__ == "__main__":
- try:
- main()
- except KeyboardInterrupt:
- print("\nBye.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement