By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,036 Members | 1,963 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,036 IT Pros & Developers. It's quick & easy.

Problems for a beginner

P: 3
I have had some basic knowledge of java through flash 8. I also use a freeware 3d software called blender. And it uses python for its game engine. So I have decided to pick up some python. This is some of my first experiences with it. So any help needs to be put in as basic of a way as possible. I believe everything is right, but when I try to run it, it says that there are problems with the tabs, and selects:
"elif x == 14:"
I don't know much about python, but I feel taht this is incorrect. I also have a problem if I take out all of the tabs, the message goes away, but a new one pops up!:
"Token Error: EOF in multi-line statement"
and then it adds a blank line at the bottom and highlights it. Please I would like to solve this problem. Any help would be much appreciated.
BTW-This is my second day messing around with python. Don't eat me alive. And I'm sure there are some easier ways of doing things then what I have done. All I need help with is the error.

Here is the code:
Expand|Select|Wrap|Line Numbers
  1. print "Formulas"
  2. print "--------------------------------------------"
  3. print "|        Welcome to Main Menu              |"
  4. print "|    Science:                              |"
  5. print "|    1.Speed                               |"
  6. print "|    2.Acceleration                        |"
  7. print "|    3.Weight                              |"
  8. print "|    4.Newton's Second Law                 |"
  9. print "|    5.Momentum                            |"
  10. print "|    6.Mechanical Advantage                |"
  11. print "|    7.Work                                |"
  12. print "|    8.Power                               |"
  13. print "|                                          |"
  14. print "|    Math:                                 |"
  15. print "|    9.Interior Angles                     |"
  16. print "|    10.Pythagorean Theorem                |"
  17. print "|    11.Area of a Circle                   |"
  18. print "|    12.Area of a Quad.                    |"
  19. print "|    13.Area of a Trapazoid                |"
  20. print "|    14.Area of a Triangle                 |"
  21. print "|    15.Area of a Rhombus/Kite             |"
  22. print "|                                          |"
  23. print "--------------------------------------------"
  24.  
  25. x = float(input("What formula would you like to use?  "))
  26.  
  27. if x == 1:
  28.     print "Speed formula"
  29.     d = float(input("What is the distance?(m)  "))
  30.     t = float(input("what is the time?(s) "))
  31.     v = (d/t)
  32.     print "The velocity is", v
  33.  
  34. elif x == 2:
  35.     print "Acceleration formula"
  36.     vf = float(input("What is the velocity final?(m/s)  "))
  37.     vi = float(input("what is the velocity initial?(m/s)  "))
  38.     t = float(input("What is the time?(s)  "))
  39.     a = (vf-vi)/t
  40.     print "The acceleration is", a
  41.  
  42. elif x == 3:
  43.     print "Weight formula"
  44.     m = float(input("What is the mass?(Kg)  "))
  45.     g = 9.8
  46.     f = (m*g)
  47.     print "The weight is", f
  48.  
  49. elif x == 4:
  50.     print "F=ma"
  51.     m = float(input("What is the mass?(Kg)  "))
  52.     a = float(input("what is the acceleration?  "))
  53.     f = (m*a)
  54.     print "The force is", f
  55.  
  56. elif x == 5:
  57.     print "Momentum formula"
  58.     m = float(input("What is the mass?(Kg)  "))
  59.     v = float(input("What is the velocity?(m/s)  "))
  60.     p = (m*v)
  61.     print "The momentum is", f
  62.  
  63. elif x == 6:
  64.     print "Mechanical Advantage"
  65.     fi = float(input("What is the force input?(N)  "))
  66.     fo = float(input("What is the force output?(N)  "))
  67.     ma = (fo/fi)
  68.     print "The mechanical advantage is", ma
  69.  
  70. elif x == 7:
  71.     print "Work formula"
  72.     f = float(input("What is the force?(N)  "))
  73.     d = float(input("What is the distance?(m)  "))
  74.     w = (f*d)
  75.     print "The work done is", w
  76.  
  77. elif x == 8:
  78.     print "Power formula"
  79.     w = float(input("What is the work?(J)  "))
  80.     t = float(input("What is the time?(s)  "))
  81.     p = (w/t)
  82.     print "The power is", p
  83.  
  84. elif x == 9:
  85.     print "Interior measures of an n sided regular polygon"
  86.     n = float(input("How many sides on the polygon: "))
  87.     degrees = ((n-2)*180)/n
  88.     print degrees
  89.     if n == 3:
  90.         print "Triangle"
  91.     if n == 4:
  92.         print "Quadrilateral"
  93.     if n == 5:
  94.         print "Pentagon"
  95.     if n == 6:
  96.         print "Hexagon"
  97.     if n == 7:
  98.         print "Heptagon"
  99.     if n == 8:
  100.         print "Octagon"
  101.     if n == 9:
  102.         print "Nonagon"
  103.     if n == 10:
  104.         print "Decagon"
  105.     if n == 11:
  106.         print "Hendecagon"
  107.     if n == 12:
  108.         print "Dodecagon"
  109.     if n == 13:
  110.         print "Tridecagon"
  111.     if n == 14:
  112.         print "Tetradecagon"
  113.     if n == 15:
  114.         print "Pentadecagon"
  115.     if n == 16:
  116.         print "Hexadecagon"
  117.     if n == 17:
  118.         print "Heptadecagon"
  119.     if n == 18:
  120.         print "Octadecagon"
  121.     if n == 19:
  122.         print "Nonadecagon"
  123.     if n == 20:
  124.         print "Icosagon"
  125.  
  126. elif x == 10:
  127.     print "Pythagorean Theorem"
  128.     a = float(input("What is the length of A:  "))
  129.     b = float(input("What is the length of B:  "))
  130.     c = (a*a) + (b*b)
  131.     c = c**0.5
  132.     print c
  133.  
  134. elif x == 11:
  135.     print "Area of a Circle"
  136.     r = float(input("What is the radius?  "))
  137.     p = 3.14
  138.     a = p*r*r
  139.     print "The area is", a
  140.  
  141. elif x == 12:
  142.     print "Area of a Quad."
  143.     b = float(input("What is the base length?  "))
  144.     h = float(input("What is the height length?  "))
  145.     a = (b*h)
  146.     print "The area is", a
  147.  
  148. elif x == 13:
  149.     print "Area of a Trapazoid"
  150.     b1 = float(input("What is the bottom base length?  "))
  151.     b2 = float(input("What is the top base length?  "))
  152.     h = float(input("What is the height length?  "))
  153.     a = ((b1+b2)*h)/2)
  154.     print "The area is", a
  155.  
  156. elif x == 14:
  157.     print "Area of a Triangle"
  158.     b = float(input("What is the base length?  "))
  159.     h = float(input("What is the height length?  "))
  160.     a = (b/2)*h
  161.     print "The area is", a
  162.  
  163. else x == 15:
  164.     print "Area of a Rhombus/Kite"
  165.     d1 = float(input("What is the length of the larger diagonal?  "))
  166.     d2 = float(input("What is the length of the smaller diagonal?  "))
  167.     a = (d1*d2)/2
  168.     print "The area is", a
  169.  
Normally the menu lines up, it is not a problem.
Apr 9 '08 #1
Share this Question
Share on Google+
5 Replies


Smygis
100+
P: 126
One misstake you have made (I havent run any of the code, And i wont cuz im in a hurry).

Expand|Select|Wrap|Line Numbers
  1. else x == 15:
Else is not suposed to have any boolean statments. Replace it with someting like this:

Expand|Select|Wrap|Line Numbers
  1. elif x == 15:
  2.     #youre code here.
  3.  
  4. else:
  5.     print "Numer %d not in range." % x
Apr 9 '08 #2

jlm699
100+
P: 314
Make Smygis' suggested change and then there is a syntax error on line 153 where it reads: a = ((b1+b2)*h)/2)
There is an extra closing parenthesis so you should either remove it or add an extra opening parenthesis where appropriate
Apr 9 '08 #3

P: 3
Thanks guys, it worked perfect. The only thing I would like to add now it to repeat the question for what number on the menu, but I don't want to repeat all of the code. I read a little bit about loops, but I am not sure how to make it. Like right before x is defined so when the first math function is made, it will ask again if you want to use another function. Then repeating all of the code without typing it out again. How is this possible?
Apr 10 '08 #4

bvdet
Expert Mod 2.5K+
P: 2,851
Something like this:
Expand|Select|Wrap|Line Numbers
  1. while True:
  2.     print "Formulas"
  3.     print "--------------------------------------------"
  4.     ....................
  5.     print " |    16.Exit                               |
  6.     print "--------------------------------------------"
  7.  
  8.     x = int(raw_input("What formula would you like to use?  "))
  9.  
  10.     if x == 1:
  11.         .......
  12.     if x == 16:
  13.         break
I suggest using raw_input, which always returns a string. If you create a function for your code, you can substitute return for break.
Apr 10 '08 #5

P: 3
Thanks, it worked perfectly!
Apr 11 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.