Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ''' calculate basic laws of motion '''
- import random
- import sys
- import os
- def isfloat(value):
- ''' check argument string contains a valid float or integer, return True or False accordingly '''
- if value.isnumeric(): return True
- try:
- float(value)
- except ValueError:
- return False
- else:
- return True
- def getfloat(prompt):
- ''' display argument prompt, keep going until valid numeric input entered, return float cast of input '''
- while True:
- user_entry = input(prompt)
- if isfloat(user_entry):
- return float(user_entry)
- else:
- print('That is not a valid input. Try again.')
- print("Laws of motion")
- print("Calculate if v=v0+at")
- v0 = getfloat('Enter v0: ')
- a = 9.8
- t = getfloat("Enter t: ")
- v = v0 + a * t
- print('v = ', v)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement