Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- # 5 possible values calculated in SUVAT equations
- variables = ["s", "u", "v", "a", "t"]
- # # # # # # Choosing the variable the user wants to calculate # # # # # #
- while True:
- # choice1 is what the user is looking to calculate
- choice1 = raw_input("Welcome to Mattin's SUVAT Simulator! Choose the value you are trying to find. You can pick from " + str(variables))
- if choice1 in variables:
- print "You have chosen to find", choice1
- variables = [v for v in variables if v != choice1] # Will delete the chosen variable from the list
- break
- # This error message will show if the input did not match any item in the list
- else:
- print "Sorry, I didn't understand that, try again. Make sure your spelling is correct (Case Sensitive), and that you did not inlcude the quotation marks."
- # # # # # # # Chosing the Variables the user already has values for # # # # # # # #
- while True:
- choice2 = raw_input("Choose the first of the values you already have. You can pick from " + str(variables))
- if choice2 in variables:
- print "You have chosen", choice2
- variables = [v for v in variables if v != choice2] # Will delete the chosen variable from the list
- break
- # This error message will show if the input did not match any item in the list
- else:
- print "Sorry, I didn't understand that, try again. Make sure your spelling is correct (Case Sensitive), and that you did not inlcude the quotation marks."
- while True:
- choice3 = raw_input("Choose the second of values you already have. You can pick from " + str(variables))
- if choice3 in variables:
- print "You have chosen", choice3
- variables = [v for v in variables if v != choice3] # Will delete the chosen variable from the list
- break
- # This error message will show if the input did not match any item in the list
- else:
- print "Sorry, I didn't understand that, try again. Make sure your spelling is correct (Case Sensitive), and that you did not inlcude the quotation marks."
- while True:
- choice4 = raw_input("Choose the third of values you already have. You can pick from " + str(variables))
- if choice4 in variables:
- print "You have chosen", choice4
- variables = [v for v in variables if v != choice4] # Will delete the chosen variable from the list
- break
- # This error message will show if the input did not match any item in the list
- else:
- print "Sorry, I didn't understand that, try again. Make sure your spelling is correct (Case Sensitive), and that you did not inlcude the quotation marks."
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
- # #################################------------###################################
- # ################################# v = u + at ###################################
- # #################################------------###################################
- if variables[0] == "s": # This will be the only item in the list if the user has chosen the other 4 already, as they get removed when chosen
- # # # Finding Values # # #
- if choice1 == "u":
- while True: # Will loop this code until they enter a valid number
- v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(v) # Testing to see if they inputted a number
- print "v is " + str(v) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(a)
- print "a is " + str(a) + " ms^-2"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(t)
- print "t is " + str(t) + " s"
- break
- except:
- print"You must enter a number. Don't include units!"
- u = float(v) - float(a) * float(t) # Rearranging the equation to give u as the answer
- print "u =", u, "ms^-1"
- elif choice1 == "v":
- while True:
- u = raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(u)
- print "u is " + str(u) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(a)
- print "a is " + str(a) + " ms^-2"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(t)
- print "time is" + str(t) + " s"
- break
- except:
- print"You must enter a number. Don't include units!"
- v = float(u) + float(a) * float(t)
- print "v = ", v, "ms^-1"
- elif choice1 == "a":
- while True:
- u = raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(u)
- print "u is " + str(u) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(v)
- print "v is " + str(v) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(t)
- print "t " + str(t) + " s"
- break
- except:
- print"You must enter a number. Don't include units!"
- a = (float(v) - float(u)) / float(t)
- print "a =", a, "ms^-2"
- elif choice1 =="t":
- while True:
- u = raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(u)
- print "u is " + str(u) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(v)
- print "v is " + str(v) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(a)
- print "a is " + str(a) + " ms^-2"
- break
- except:
- print"You must enter a number. Don't include units!"
- t = (float(v) - float(u)) / float(a)
- print "t =", t, "s"
- # ##############################------------------###############################
- # ############################# s = vt - 1/2 at^2 ###############################
- # #############################-------------------###############################
- if variables[0] == "u":
- if choice1 =="s":
- while True:
- v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(v)
- print "v is " + str(v) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(a)
- print "a is " + str(a) + " ms^-2"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(t)
- print "t is " + str(t) + " s"
- break
- except:
- print"You must enter a number. Don't include units!"
- s = float(v) * float(t) - (float(a) * float(t)**2) / 2
- print "s =", s, "m"
- elif choice1 == "v":
- while True:
- s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(s)
- print "s is " + str(s) + " m"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(a)
- print "a is " + str(a) + " ms^-2"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(t)
- print "time " + str(t) + " s"
- break
- except:
- print"You must enter a number. Don't include units!"
- v = ((float(a) * float(t)) / 2) +(float(s) / float(t))
- print "v =", v, "ms^-1"
- elif choice1 == "a":
- while True:
- s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(s)
- print "s is " + str(s) + " m"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(v)
- print "v is " + str(v) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(t)
- print "t " + str(t) + " s"
- break
- except:
- print"You must enter a number. Don't include units!"
- a = ((-2)(float(s) - float(v) * float(t))) / float(t)**2
- print "a =", a, "ms^-2"
- elif choice1 =="t":
- while True:
- s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(s)
- print "u is " + str(s) + " m"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(v)
- print "v is " + str(v) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(a)
- print "a is " + str(a) + " ms^-2"
- break
- except:
- print"You must enter a number. Don't include units!"
- try:
- t = (float(v) - math.sqrt(float(v)**2 - (2 * float(a) * float(s))))/ float(a)
- print "t =", t,"s"
- except ValueError:
- print "ERROR: Cannot sqrt a negative number. You must enter your values again. "
- # ####################################--------------------#################################
- # #################################### s = ut + 1/2 at^2 ##################################
- # ###################################--------------------##################################
- if variables[0] == "v":
- if choice1 =="s":
- while True:
- u = raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(u)
- print "u is " + str(u) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(a)
- print "a is " + str(a) + " ms^-2"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(t)
- print "t is " + str(t) + " s"
- break
- except:
- print"You must enter a number. Don't include units!"
- s = float(u) * float(t) + (float(a) * float(t)**2) / 2
- print "s =", s, "m"
- elif choice1 =="u":
- while True:
- s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(s)
- print "s is " + str(s) + " m"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(a)
- print "a is " + str(a) + " ms^-2"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(t)
- print "t is " + str(t) + " s"
- break
- except:
- print"You must enter a number. Don't include units!"
- u = (float(s) / float(t)) - (float(a) * float(t)) / 2
- print "u=", u, "ms^-1"
- elif choice1 =="a":
- while True:
- s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(s)
- print "s is " + str(s) + " m"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- u = raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(u)
- print "u is " + str(u) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(t)
- print "t is " + str(t) + " s"
- break
- except:
- print"You must enter a number. Don't include units!"
- a = (2(float(s) - (float(u) * float(t)))) / float(t)**2
- print "a =", a, "ms^-2"
- elif choice1 =="t":
- while True:
- s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(s)
- print "s is " + str(s) + " m"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(a)
- print "a is " + str(a) + " ms^-2"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- u = raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(u)
- print "u is " + str(u) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- try:
- t = (math.sqrt((2 * float(a) * float(s)) + float(u)**2) + float(u)) / float(a)
- print "t =", t, "s"
- except ValueError:
- print "ERROR: Cannot sqrt a negative number. You must enter your values again. "
- # ################################-------------------##############################
- # ############################### s = ((v + u) / 2)t ##############################
- # ###############################--------------------##############################
- if variables[0] == "a":
- if choice1 =="s":
- while True:
- v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(v)
- print "v is " + str(v) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- u = raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(u)
- print "u is " + str(u) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(t)
- print "t is " + str(t) + " s"
- break
- except:
- print"You must enter a number. Don't include units!"
- s = ((float(v) + float(u)) / 2) * float(t)
- print "s =", s, "m"
- elif choice1 =="u":
- while True:
- s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(s)
- print "s is " + str(s) + " m"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- v= raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(v)
- print "v is " + str(v) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(t)
- print "t is " + str(t) + " s"
- break
- except:
- print"You must enter a number. Don't include units!"
- u = (2 * float(s) / float(t)) - float(v)
- print "u =", u, "ms^-1"
- elif choice1 == "v":
- while True:
- s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(s)
- print "s is " + str(s) + " m"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- u= raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(u)
- print "u is " + str(u) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(t)
- print "t is " + str(t) + " s"
- break
- except:
- print"You must enter a number. Don't include units!"
- v = (2 * float(s) / float(t)) - float(u)
- print "v =", v, "ms^-1"
- elif choice1 == "t":
- while True:
- s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(s)
- print "s is " + str(s) + " m"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- u= raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(u)
- print "u is " + str(u) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(a)
- print "a is " + str(a) + " ms^-2"
- break
- except:
- print"You must enter a number. Don't include units!"
- t = float(s) - ((float(v) +float(u)) / 2)
- # ###################################-----------------###############################
- # ################################### v^2 = u^2 + 2as ###############################
- # ###################################-----------------###############################
- if variables[0] == "t":
- if choice1 == "s":
- while True:
- a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(a)
- print "a is " + str(a) + " ms^-2"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- u= raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(u)
- print "u is " + str(u) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(v)
- print "v is " + str(v) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- s = (float(v)**2 - float(u)**2) / 2 * float(a)
- print "s =", s, "m"
- if choice1 == "u":
- while True:
- a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(a)
- print "a is " + str(a) + " ms^-2"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- s= raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(s)
- print "s is " + str(s) + " m"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(v)
- print "v is " + str(v) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- try:
- u = math.sqrt(float(v)**2 - 2(float(a) * float(s)))
- print "u =", u, "ms^-1"
- except ValueError:
- print "ERROR: Cannot sqrt a negative number. You must enter your values again. "
- if choice1 == "v":
- while True:
- a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(a)
- print "a is " + str(a) + " ms^-2"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- u= raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(u)
- print "u is " + str(u) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(v)
- print "s is " + str(s) + " m"
- break
- except:
- print"You must enter a number. Don't include units!"
- try:
- v = math.sqrt(float(u)**2 + 2 * float(a) * float(s))
- print "v =", v, "ms^-1"
- except ValueError:
- print "ERROR Cannot sqrt a negative number. You must enter your values again. "
- if choice1 == "a":
- while True:
- s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(s)
- print "s is " + str(s) + " m"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- u= raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(u)
- print "u is " + str(u) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- while True:
- v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
- try:
- float(v)
- print "v is " + str(v) + " ms^-1"
- break
- except:
- print"You must enter a number. Don't include units!"
- a = (float(v)**2 - float(u)**2) / 2 * float(s)
- print "a =", a, "ms^-2"
- raw_input("Thank you for using Mattin's SUVAT simulator. Hit enter to end the program.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement