from random import *
from math import *
rate_of_change = round(sqrt(randint(1,100)),1)*(-1)**randint(-5,5)
initial_x = round(sqrt(randint(1,100)),1)
initial_t = randint(-2,10)
delta_t = 0.5
current_t = initial_t
current_x = initial_x
def get_float(message):
answer = ''
while(not type(answer) == float):
answer = ''
try:
answer = float(raw_input(message))
except ValueError:
print 'Please enter a decimal answer.'
print "\n"
return answer
for i in range(10):
print "Time: %0.2f seconds, Position: %0.2f meters"%(current_t, current_x)
current_t = current_t + delta_t
current_x = current_x + rate_of_change*delta_t
predict_t = current_t + randint(1,6)*delta_t
answer_accepted = False
answer = ''
print "What will the position be at t = %0.2f seconds?"%(predict_t)
predict_x = (predict_t - current_t)*rate_of_change + current_x
answer = get_float('Enter your answer: ')
if(abs(answer-predict_x)<0.05):
print "Nice job, you predicted correctly!"
else:
print "I'm sorry, your prediction was not correct. The correct answer is %0.2f meters."%(predict_x)