# Kinematic-o-matic!!
# By Zack, Austin, Kerry, Isabel & Tristan

from distutils.util import strtobool
import math

# GetUserInfoFor2(String name, int spaces): Prompts user on a value
#	Returns the value, or False if null returned
#	V2: Prettier. :)
def GetUserInfoFor2(name, spaces):
	# Print prompt
	print("The "+name+" is", end="")
	for x in range(0, spaces):
		print(" ", end="")
	print(": ", end="")
	# It's a loop because it will repeat if the user enters something invalid.
	while True:
		# Catch input
		raw_input = input().lower()
		# If is empty, return False
		if raw_input is "":
			return False # The first way this loop is exited
		# Is it a number?
		try:
			return float(raw_input) # The second way this loop it exited
		except ValueError:
			print("     Please type a number or leave blank if you don't know! :", end="")





# valueOrUnknown: Returns the value as a string, or "unknown" if value is False.
def valueOrUnknown(val):
	if val is False:
		return "unknown"
	return str(val)

def dumpall():
	print("The initial position is : "+valueOrUnknown(x_i))
	print("The initial velocity is : "+valueOrUnknown(v_i))
	print("The accelaration is     : "+valueOrUnknown(a))
	print("The time is             : "+valueOrUnknown(t))
	print("The displacement is     : "+valueOrUnknown(d))
	print("The final position is   : "+valueOrUnknown(x_f))
	print("The final velocity is   : "+valueOrUnknown(v_f))











#Starting high-level code! :)

#Greeting
print(
"-----------------------------------------------\n"+
"|      Welcome to the Kinematic-o-matic!      |\n"+
"|   By Zack, Austin, Kerry, Isabel & Tristan  |\n"+
"-----------------------------------------------") 

# Input all variables
x_i = GetUserInfoFor2("initial position", 1)
v_i = GetUserInfoFor2("initial velocity", 1)
a   = GetUserInfoFor2("accelaration", 5)
t   = GetUserInfoFor2("time", 13)
d   = GetUserInfoFor2("displacement", 5)
x_f = GetUserInfoFor2("final position", 3)
v_f = GetUserInfoFor2("final velocity", 3)

# Repeatedly try to figure stuff out.
#     Every iteration, it figures out one more variable, then goes back to the top of the loop.
#     If it ever gets to the end of the while loop, it can't figure anything else out, and gives up
while True:
	if x_i is not False and v_i is not False and a is not False and t is not False and d is not False and x_f is not False and v_f is not False:
		#We know everything; break out of the loop
		break
	
	# Trying to find initial position!
	if x_i is False:
		# d = x_f - x_i
		# x_i = x_f - d
		if d is not False and x_f is not False:
			x_i = x_f - d
			continue
	
	# Try to find initial velocity!
	if v_i is False:
		# d = v_i*t + 0.5*a*t^2
		# v_i = (d - 0.5*a*t^2)/t
		if d is not False and a is not False and t is not False and t!=0:
			v_i = (d-0.5*a*t*t)/t
			continue
		# v_f = v_i + a*t
		# v_i = v_f - a*t
		if v_f is not False and a is not False and t is not False:
			v_i = v_f-a*t
			continue
		# d = (v_i+v_f)/2 * t
		# v_i = d/t*2-v_f
		if d is not False and t is not False and v_f is not False and (t*2-v_f)!=0:
			v_i = d/t*2-v_f
			continue
		# Would normally be second, moved to last due to being sign-insensitive
		# v_f^2 = v_i^2 + 2*a*d
		# v_i = sqrt(v_f^2 - 2*a*d)
		if v_f is not False and a is not False and d is not False and (v_f**2 - 2*a*d)>=0:
			v_i = math.sqrt(v_f**2 - 2*a*d)
			continue
	
	# Try to find accelaration!
	if a is False:
		# d = v_i*t + 0.5*a*t^2
		# d-v_i*t = 0.5*a*t^2
		# a = 2*(d-v_i*t)/(t^2)
		if d is not False and v_i is not False and t is not False and t**2!=0:
			a = 2*(d - v_i*t)/(t*t)
			continue
		# v_f = v_i + a*t
		# a = (v_f - v_i)/t
		print(t)
		if v_f is not False and v_i is not False and t is not False and t!=0:
			a = (v_f - v_i)/t
			continue
	
	# Try to find time!
	if t is False:
		# v_f = v_i + a*t
		# t = (v_f-v_i)/a
		if v_f is not False and v_i is not False and a is not False and a!=0:
			t = (v_f-v_i)/a
			continue
		# d = (v_i + v_f)/2 * t
		# t = 2d/(v_i+v_f)
		if d is not False and v_i is not False and v_f is not False and (v_i+v_f)!=0:
			t = 2*d/(v_i+v_f)
			continue
		# EXTRA SPECIAL ONE if a==0!!
		# d = v_i*t
		# t = d/v_i
		if d is not False and v_i is not False and a==0 and v_i!=0:
			t = d/v_i
			continue
		# Would normally be first, but was moved to last due to being sign-insensitive
		# d = v_i*t + 0.5*a*t^2
		# Solved w/ Wolfram Alpha (http://www.wolframalpha.com/input/?i=solve+d%3Dv*t+%2B+a*t%5E2%2F2+for+t)
		if a is not False and d is not False and v_i is not False and a!=0:
			t = -(math.sqrt(2*a*d+v_i*v_i)+v_i)/a
			if t<0:
				t = (math.sqrt(2*a*d+v_i*v_i)-v_i)/a
			continue
	
	# Try to find displacement!
	if d is False:
		# d = x_f-x_i
		if x_f is not False and x_i is not False:
			d = x_f-x_i
			continue
		# d = v_i*t + 0.5*a*t^2
		if v_i is not False and t is not False and a is not False:
			d = v_i*t+a*t*t/2
			continue
		# v_f^2 = v_i^2 + 2*a*d
		# d = (v_f^2 - v_i^2)/(2*a)
		if v_f is not False and v_i is not False and a is not False and a!=0:
			d = (v_f**2 - v_i**2)/a/2
			continue
		# d = (v_i+v_f)/2*t
		if v_i is not False and v_f is not False and t is not False:
			d = (v_i+v_f)/2*2
			continue
	
	#Try to find final position!
	if x_f is False:
		# x_f = x_i+d
		if x_i is not False and d is not False:
			x_f = x_i+d
			continue
	
	#Try to find final velocity!
	if v_f is False:
		# v_f = v_i + a*t
		if v_i is not False and a is not False and t is not False:
			v_f = v_i+a*t
			continue
		# d = (v_i+v_f)/2*t
		# v_f = 2d/t-v_i
		if d is not False and t is not False and v_i is not False and t!=0:
			v_f = 2*d/t-v_i
			continue
		# This would normally be first, but was moved to last due to being sign-insensitive.
		# v_f^2 = v_i^2 + 2*a*d
		# v_f = sqrt(v_i^2 + 2*a*d)
		if v_i is not False and a is not False and d is not False and (v_i**2 + 2*a*d)>=0:
			v_f = math.sqrt(v_i**2 + 2*a*d)
			continue
	
	#Can't figure anything else out; break out of the loop
	break


#Add two blank lines
print("\n----------RESULTS----------")

#Print everything we know
dumpall()
