Advertisement
Guest User

SUVAT Simulator

a guest
Apr 11th, 2013
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 28.15 KB | None | 0 0
  1.  
  2. import math
  3.  
  4. # 5 possible values calculated in SUVAT equations
  5. variables = ["s", "u", "v", "a", "t"]
  6.  
  7.  
  8. # # # # # # Choosing the variable the user wants to calculate # # # # # #
  9.  
  10. while True:
  11.     # choice1 is what the user is looking to calculate
  12.     choice1 = raw_input("Welcome to Mattin's SUVAT Simulator! Choose the value you are trying to find. You can pick from " + str(variables))
  13.     if choice1 in variables:
  14.         print "You have chosen to find", choice1
  15.         variables = [v for v in variables if v != choice1] # Will delete the chosen variable from the list
  16.         break
  17.  
  18. # This error message will show if the input did not match any item in the list
  19.     else:
  20.         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."
  21.  
  22.  
  23. # # # # # # # Chosing the Variables the user already has values for # # # # # # # #
  24.  
  25.  
  26. while True:
  27.     choice2 = raw_input("Choose the first of the values you already have. You can pick from " + str(variables))
  28.     if choice2 in variables:
  29.         print "You have chosen", choice2
  30.         variables = [v for v in variables if v != choice2] # Will delete the chosen variable from the list
  31.         break
  32. # This error message will show if the input did not match any item in the list
  33.     else:
  34.         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."
  35.  
  36.  
  37. while True:
  38.     choice3 = raw_input("Choose the second of values you already have. You can pick from " + str(variables))
  39.     if choice3 in variables:
  40.         print "You have chosen", choice3
  41.         variables = [v for v in variables if v != choice3] # Will delete the chosen variable from the list
  42.         break
  43. # This error message will show if the input did not match any item in the list
  44.     else:
  45.         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."
  46.  
  47. while True:
  48.     choice4 = raw_input("Choose the third of values you already have. You can pick from " + str(variables))
  49.     if choice4 in variables:
  50.         print "You have chosen", choice4
  51.         variables = [v for v in variables if v != choice4] # Will delete the chosen variable from the list
  52.         break
  53. # This error message will show if the input did not match any item in the list
  54.     else:
  55.         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."
  56.  
  57.  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  58.  
  59.  
  60.  
  61. # #################################------------###################################
  62. # ################################# v = u + at ###################################
  63. # #################################------------###################################
  64.  
  65. 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
  66.  
  67. # # # Finding Values  # # #
  68.  
  69.  
  70.     if choice1 == "u":
  71.  
  72.         while True: # Will loop this code until they enter a valid number
  73.             v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
  74.             try:
  75.                 float(v) # Testing to see if they inputted a number
  76.                 print "v is " + str(v) + " ms^-1"
  77.                 break
  78.             except:
  79.                 print"You must enter a number. Don't include units!"
  80.  
  81.         while True:
  82.             a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
  83.             try:
  84.                 float(a)
  85.                 print "a is " + str(a) + " ms^-2"
  86.                 break
  87.             except:
  88.                 print"You must enter a number. Don't include units!"
  89.  
  90.         while True:
  91.             t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
  92.             try:
  93.                 float(t)
  94.                 print "t is " + str(t) + " s"
  95.                 break
  96.             except:
  97.                 print"You must enter a number. Don't include units!"
  98.  
  99.         u =  float(v) - float(a) * float(t) # Rearranging the equation to give u as the answer
  100.         print "u =", u, "ms^-1"
  101.  
  102.  
  103.     elif choice1 == "v":
  104.  
  105.         while True:
  106.             u = raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
  107.             try:
  108.                 float(u)
  109.                 print "u is " + str(u) + " ms^-1"
  110.                 break
  111.             except:
  112.                 print"You must enter a number. Don't include units!"
  113.  
  114.         while True:
  115.             a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
  116.             try:
  117.                 float(a)
  118.                 print "a is " + str(a) + " ms^-2"
  119.                 break
  120.             except:
  121.                 print"You must enter a number. Don't include units!"
  122.  
  123.         while True:
  124.             t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
  125.             try:
  126.                 float(t)
  127.                 print "time is" + str(t) + " s"
  128.                 break
  129.             except:
  130.                 print"You must enter a number. Don't include units!"
  131.  
  132.         v = float(u) + float(a) * float(t)
  133.         print "v = ", v, "ms^-1"
  134.  
  135.     elif choice1 == "a":
  136.  
  137.         while True:
  138.             u = raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
  139.             try:
  140.                 float(u)
  141.                 print "u is " + str(u) + " ms^-1"
  142.                 break
  143.             except:
  144.                 print"You must enter a number. Don't include units!"
  145.  
  146.         while True:
  147.             v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
  148.             try:
  149.                 float(v)
  150.                 print "v is " + str(v) + " ms^-1"
  151.                 break
  152.             except:
  153.                 print"You must enter a number. Don't include units!"
  154.  
  155.         while True:
  156.             t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
  157.             try:
  158.                 float(t)
  159.                 print "t " + str(t) + " s"
  160.                 break
  161.             except:
  162.                 print"You must enter a number. Don't include units!"
  163.  
  164.         a = (float(v) - float(u)) / float(t)
  165.         print "a =", a, "ms^-2"
  166.  
  167.     elif choice1 =="t":
  168.  
  169.         while True:
  170.             u = raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
  171.             try:
  172.                 float(u)
  173.                 print "u is " + str(u) + " ms^-1"
  174.                 break
  175.             except:
  176.                 print"You must enter a number. Don't include units!"
  177.  
  178.         while True:
  179.             v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
  180.             try:
  181.                 float(v)
  182.                 print "v is " + str(v) + " ms^-1"
  183.                 break
  184.             except:
  185.                 print"You must enter a number. Don't include units!"
  186.  
  187.         while True:
  188.             a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
  189.             try:
  190.                 float(a)
  191.                 print "a is " + str(a) + " ms^-2"
  192.                 break
  193.             except:
  194.                 print"You must enter a number. Don't include units!"
  195.  
  196.         t = (float(v) - float(u)) / float(a)
  197.         print "t =", t, "s"
  198.  
  199. # ##############################------------------###############################
  200. # ############################# s = vt - 1/2 at^2 ###############################
  201. # #############################-------------------###############################
  202.  
  203.  
  204. if variables[0] == "u":
  205.  
  206.     if choice1 =="s":
  207.  
  208.         while True:
  209.             v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
  210.             try:
  211.                 float(v)
  212.                 print "v is " + str(v) + " ms^-1"
  213.                 break
  214.             except:
  215.                 print"You must enter a number. Don't include units!"
  216.  
  217.         while True:
  218.             a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
  219.             try:
  220.                 float(a)
  221.                 print "a is " + str(a) + " ms^-2"
  222.                 break
  223.             except:
  224.                 print"You must enter a number. Don't include units!"
  225.  
  226.         while True:
  227.             t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
  228.             try:
  229.                 float(t)
  230.                 print "t is " + str(t) + " s"
  231.                 break
  232.             except:
  233.                 print"You must enter a number. Don't include units!"
  234.  
  235.         s = float(v) * float(t) - (float(a) * float(t)**2) / 2
  236.         print "s =", s, "m"
  237.  
  238.  
  239.     elif choice1 == "v":
  240.  
  241.         while True:
  242.             s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
  243.             try:
  244.                 float(s)
  245.                 print "s is " + str(s) + " m"
  246.                 break
  247.             except:
  248.                 print"You must enter a number. Don't include units!"
  249.  
  250.         while True:
  251.             a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
  252.             try:
  253.                 float(a)
  254.                 print "a is " + str(a) + " ms^-2"
  255.                 break
  256.             except:
  257.                 print"You must enter a number. Don't include units!"
  258.  
  259.         while True:
  260.             t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
  261.             try:
  262.                 float(t)
  263.                 print "time " + str(t) + " s"
  264.                 break
  265.             except:
  266.                 print"You must enter a number. Don't include units!"
  267.  
  268.         v =  ((float(a) * float(t)) / 2) +(float(s) / float(t))
  269.         print "v =", v, "ms^-1"
  270.  
  271.     elif choice1 == "a":
  272.  
  273.         while True:
  274.             s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
  275.             try:
  276.                 float(s)
  277.                 print "s is " + str(s) + " m"
  278.                 break
  279.             except:
  280.                 print"You must enter a number. Don't include units!"
  281.  
  282.         while True:
  283.             v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
  284.             try:
  285.                 float(v)
  286.                 print "v is " + str(v) + " ms^-1"
  287.                 break
  288.             except:
  289.                 print"You must enter a number. Don't include units!"
  290.  
  291.         while True:
  292.             t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
  293.             try:
  294.                 float(t)
  295.                 print "t " + str(t) + " s"
  296.                 break
  297.             except:
  298.                 print"You must enter a number. Don't include units!"
  299.  
  300.         a = ((-2)(float(s) - float(v) * float(t))) / float(t)**2
  301.         print "a =", a, "ms^-2"
  302.  
  303.     elif choice1 =="t":
  304.  
  305.         while True:
  306.             s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
  307.             try:
  308.                 float(s)
  309.                 print "u is " + str(s) + " m"
  310.                 break
  311.             except:
  312.                 print"You must enter a number. Don't include units!"
  313.  
  314.         while True:
  315.             v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
  316.             try:
  317.                 float(v)
  318.                 print "v is " + str(v) + " ms^-1"
  319.                 break
  320.             except:
  321.                 print"You must enter a number. Don't include units!"
  322.  
  323.         while True:
  324.             a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
  325.             try:
  326.                 float(a)
  327.                 print "a is " + str(a) + " ms^-2"
  328.                 break
  329.             except:
  330.                 print"You must enter a number. Don't include units!"
  331.  
  332.         try:
  333.             t = (float(v) - math.sqrt(float(v)**2 - (2 * float(a) * float(s))))/ float(a)
  334.             print "t =", t,"s"
  335.         except ValueError:
  336.             print "ERROR: Cannot sqrt a negative number. You must enter your values again. "
  337.  
  338.  
  339. # ####################################--------------------#################################
  340. # #################################### s = ut + 1/2 at^2 ##################################
  341. # ###################################--------------------##################################
  342.  
  343. if variables[0] == "v":
  344.  
  345.     if choice1 =="s":
  346.  
  347.         while True:
  348.             u = raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
  349.             try:
  350.                 float(u)
  351.                 print "u is " + str(u) + " ms^-1"
  352.                 break
  353.             except:
  354.                 print"You must enter a number. Don't include units!"
  355.  
  356.         while True:
  357.             a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
  358.             try:
  359.                 float(a)
  360.                 print "a is " + str(a) + " ms^-2"
  361.                 break
  362.             except:
  363.                 print"You must enter a number. Don't include units!"
  364.  
  365.         while True:
  366.             t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
  367.             try:
  368.                 float(t)
  369.                 print "t is " + str(t) + " s"
  370.                 break
  371.             except:
  372.                 print"You must enter a number. Don't include units!"
  373.  
  374.         s = float(u) * float(t) + (float(a) * float(t)**2) / 2
  375.         print "s =", s, "m"
  376.  
  377.     elif choice1 =="u":
  378.  
  379.         while True:
  380.             s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
  381.             try:
  382.                 float(s)
  383.                 print "s is " + str(s) + " m"
  384.                 break
  385.             except:
  386.                 print"You must enter a number. Don't include units!"
  387.  
  388.         while True:
  389.             a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
  390.             try:
  391.                 float(a)
  392.                 print "a is " + str(a) + " ms^-2"
  393.                 break
  394.             except:
  395.                 print"You must enter a number. Don't include units!"
  396.  
  397.         while True:
  398.             t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
  399.             try:
  400.                 float(t)
  401.                 print "t is " + str(t) + " s"
  402.                 break
  403.             except:
  404.                 print"You must enter a number. Don't include units!"
  405.  
  406.         u = (float(s) / float(t)) - (float(a) * float(t)) / 2
  407.         print "u=", u, "ms^-1"
  408.  
  409.     elif choice1 =="a":
  410.  
  411.         while True:
  412.             s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
  413.             try:
  414.                 float(s)
  415.                 print "s is " + str(s) + " m"
  416.                 break
  417.             except:
  418.                 print"You must enter a number. Don't include units!"
  419.  
  420.         while True:
  421.             u = raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
  422.             try:
  423.                 float(u)
  424.                 print "u is " + str(u) + " ms^-1"
  425.                 break
  426.             except:
  427.                 print"You must enter a number. Don't include units!"
  428.  
  429.         while True:
  430.             t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
  431.             try:
  432.                 float(t)
  433.                 print "t is " + str(t) + " s"
  434.                 break
  435.             except:
  436.                 print"You must enter a number. Don't include units!"
  437.  
  438.         a = (2(float(s) - (float(u) * float(t)))) / float(t)**2
  439.         print "a =", a, "ms^-2"
  440.  
  441.  
  442.     elif choice1 =="t":
  443.  
  444.         while True:
  445.             s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
  446.             try:
  447.                 float(s)
  448.                 print "s is " + str(s) + " m"
  449.                 break
  450.             except:
  451.                 print"You must enter a number. Don't include units!"
  452.  
  453.         while True:
  454.             a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
  455.             try:
  456.                 float(a)
  457.                 print "a is " + str(a) + " ms^-2"
  458.                 break
  459.             except:
  460.                 print"You must enter a number. Don't include units!"
  461.  
  462.         while True:
  463.             u = raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
  464.             try:
  465.                 float(u)
  466.                 print "u is " + str(u) + " ms^-1"
  467.                 break
  468.             except:
  469.                 print"You must enter a number. Don't include units!"
  470.  
  471.  
  472.         try:
  473.             t =  (math.sqrt((2 * float(a) * float(s)) + float(u)**2) + float(u)) / float(a)
  474.             print "t =", t, "s"
  475.         except ValueError:
  476.             print "ERROR: Cannot sqrt a negative number. You must enter your values again. "
  477.  
  478.  
  479. # ################################-------------------##############################
  480. # ############################### s = ((v + u) / 2)t ##############################
  481. # ###############################--------------------##############################
  482.  
  483. if variables[0] == "a":
  484.  
  485.     if choice1 =="s":
  486.  
  487.         while True:
  488.             v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
  489.             try:
  490.                 float(v)
  491.                 print "v is " + str(v) + " ms^-1"
  492.                 break
  493.             except:
  494.                 print"You must enter a number. Don't include units!"
  495.  
  496.         while True:
  497.             u = raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
  498.             try:
  499.                 float(u)
  500.                 print "u is " + str(u) + " ms^-1"
  501.                 break
  502.             except:
  503.                 print"You must enter a number. Don't include units!"
  504.  
  505.         while True:
  506.             t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
  507.             try:
  508.                 float(t)
  509.                 print "t is " + str(t) + " s"
  510.                 break
  511.             except:
  512.                 print"You must enter a number. Don't include units!"
  513.  
  514.         s = ((float(v) + float(u)) / 2) * float(t)
  515.         print "s =", s, "m"
  516.  
  517.     elif choice1 =="u":
  518.  
  519.         while True:
  520.             s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
  521.             try:
  522.                 float(s)
  523.                 print "s is " + str(s) + " m"
  524.                 break
  525.             except:
  526.                 print"You must enter a number. Don't include units!"
  527.  
  528.         while True:
  529.             v= raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
  530.             try:
  531.                 float(v)
  532.                 print "v is " + str(v) + " ms^-1"
  533.                 break
  534.             except:
  535.                 print"You must enter a number. Don't include units!"
  536.  
  537.         while True:
  538.             t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
  539.             try:
  540.                 float(t)
  541.                 print "t is " + str(t) + " s"
  542.                 break
  543.             except:
  544.                 print"You must enter a number. Don't include units!"
  545.  
  546.         u = (2 * float(s) / float(t)) - float(v)
  547.         print "u =", u, "ms^-1"
  548.  
  549.     elif choice1 == "v":
  550.  
  551.         while True:
  552.             s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
  553.             try:
  554.                 float(s)
  555.                 print "s is " + str(s) + " m"
  556.                 break
  557.             except:
  558.                 print"You must enter a number. Don't include units!"
  559.  
  560.         while True:
  561.             u= raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
  562.             try:
  563.                 float(u)
  564.                 print "u is " + str(u) + " ms^-1"
  565.                 break
  566.             except:
  567.                 print"You must enter a number. Don't include units!"
  568.  
  569.         while True:
  570.             t = raw_input("What is the value of t? Make sure it is in standard units, however, do not include the unit.")
  571.             try:
  572.                 float(t)
  573.                 print "t is " + str(t) + " s"
  574.                 break
  575.             except:
  576.                 print"You must enter a number. Don't include units!"
  577.  
  578.         v = (2 * float(s) / float(t)) - float(u)
  579.         print "v =", v, "ms^-1"
  580.  
  581.  
  582.     elif  choice1 == "t":
  583.  
  584.         while True:
  585.             s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
  586.             try:
  587.                 float(s)
  588.                 print "s is " + str(s) + " m"
  589.                 break
  590.             except:
  591.                 print"You must enter a number. Don't include units!"
  592.  
  593.         while True:
  594.             u= raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
  595.             try:
  596.                 float(u)
  597.                 print "u is " + str(u) + " ms^-1"
  598.                 break
  599.             except:
  600.                 print"You must enter a number. Don't include units!"
  601.  
  602.         while True:
  603.             a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
  604.             try:
  605.                 float(a)
  606.                 print "a is " + str(a) + " ms^-2"
  607.                 break
  608.             except:
  609.                 print"You must enter a number. Don't include units!"
  610.  
  611.         t = float(s) - ((float(v) +float(u)) / 2)
  612.  
  613.  
  614.  
  615. # ###################################-----------------###############################
  616. # ################################### v^2 = u^2 + 2as ###############################
  617. # ###################################-----------------###############################
  618.  
  619. if variables[0] == "t":
  620.  
  621.     if choice1 == "s":
  622.  
  623.         while True:
  624.             a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
  625.             try:
  626.                 float(a)
  627.                 print "a is " + str(a) + " ms^-2"
  628.                 break
  629.             except:
  630.                 print"You must enter a number. Don't include units!"
  631.  
  632.         while True:
  633.             u= raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
  634.             try:
  635.                 float(u)
  636.                 print "u is " + str(u) + " ms^-1"
  637.                 break
  638.             except:
  639.                 print"You must enter a number. Don't include units!"
  640.  
  641.         while True:
  642.             v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
  643.             try:
  644.                 float(v)
  645.                 print "v is " + str(v) + " ms^-1"
  646.                 break
  647.             except:
  648.                 print"You must enter a number. Don't include units!"
  649.  
  650.         s = (float(v)**2 - float(u)**2) / 2 * float(a)
  651.         print "s =", s, "m"
  652.  
  653.     if choice1 == "u":
  654.  
  655.         while True:
  656.             a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
  657.             try:
  658.                 float(a)
  659.                 print "a is " + str(a) + " ms^-2"
  660.  
  661.                 break
  662.             except:
  663.                 print"You must enter a number. Don't include units!"
  664.  
  665.         while True:
  666.             s= raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
  667.             try:
  668.                 float(s)
  669.                 print "s is " + str(s) + " m"
  670.                 break
  671.             except:
  672.                 print"You must enter a number. Don't include units!"
  673.  
  674.         while True:
  675.             v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
  676.             try:
  677.                 float(v)
  678.                 print "v is " + str(v) + " ms^-1"
  679.                 break
  680.             except:
  681.                 print"You must enter a number. Don't include units!"
  682.  
  683.         try:
  684.             u = math.sqrt(float(v)**2 - 2(float(a) * float(s)))
  685.             print "u =", u, "ms^-1"
  686.         except ValueError:
  687.             print "ERROR: Cannot sqrt a negative number. You must enter your values again. "
  688.  
  689.  
  690.     if choice1 == "v":
  691.  
  692.         while True:
  693.             a = raw_input("What is the value of a? Make sure it is in standard units, however, do not include the unit.")
  694.             try:
  695.                 float(a)
  696.                 print "a is " + str(a) + " ms^-2"
  697.                 break
  698.             except:
  699.                 print"You must enter a number. Don't include units!"
  700.  
  701.         while True:
  702.             u= raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
  703.             try:
  704.                 float(u)
  705.                 print "u is " + str(u) + " ms^-1"
  706.                 break
  707.             except:
  708.                 print"You must enter a number. Don't include units!"
  709.  
  710.         while True:
  711.             s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
  712.             try:
  713.                 float(v)
  714.                 print "s is " + str(s) + " m"
  715.                 break
  716.             except:
  717.                 print"You must enter a number. Don't include units!"
  718.  
  719.         try:
  720.             v = math.sqrt(float(u)**2 + 2 * float(a) * float(s))
  721.             print "v =", v, "ms^-1"
  722.         except ValueError:
  723.             print "ERROR Cannot sqrt a negative number. You must enter your values again. "
  724.  
  725.  
  726.     if choice1 == "a":
  727.  
  728.         while True:
  729.             s = raw_input("What is the value of s? Make sure it is in standard units, however, do not include the unit.")
  730.             try:
  731.                 float(s)
  732.                 print "s is " + str(s) + " m"
  733.                 break
  734.             except:
  735.                 print"You must enter a number. Don't include units!"
  736.  
  737.         while True:
  738.             u= raw_input("What is the value of u? Make sure it is in standard units, however, do not include the unit.")
  739.             try:
  740.                 float(u)
  741.                 print "u is " + str(u) + " ms^-1"
  742.                 break
  743.             except:
  744.                 print"You must enter a number. Don't include units!"
  745.  
  746.         while True:
  747.             v = raw_input("What is the value of v? Make sure it is in standard units, however, do not include the unit.")
  748.             try:
  749.                 float(v)
  750.                 print "v is " + str(v) + " ms^-1"
  751.                 break
  752.             except:
  753.                 print"You must enter a number. Don't include units!"
  754.  
  755.         a = (float(v)**2 - float(u)**2) / 2 * float(s)
  756.         print "a =", a, "ms^-2"
  757.  
  758.  
  759.  
  760. 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