Problems for a beginner

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SpennH
    New Member
    • Apr 2008
    • 3

    Problems for a beginner

    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:
    Code:
    print "Formulas"
    print "--------------------------------------------"
    print "|        Welcome to Main Menu              |"
    print "|    Science:                              |"
    print "|    1.Speed                               |"
    print "|    2.Acceleration                        |"
    print "|    3.Weight                              |"
    print "|    4.Newton's Second Law                 |"
    print "|    5.Momentum                            |"
    print "|    6.Mechanical Advantage                |"
    print "|    7.Work                                |"
    print "|    8.Power                               |"
    print "|                                          |"
    print "|    Math:                                 |"
    print "|    9.Interior Angles                     |"
    print "|    10.Pythagorean Theorem                |"
    print "|    11.Area of a Circle                   |"
    print "|    12.Area of a Quad.                    |"
    print "|    13.Area of a Trapazoid                |"
    print "|    14.Area of a Triangle                 |"
    print "|    15.Area of a Rhombus/Kite             |"
    print "|                                          |"
    print "--------------------------------------------"
    
    x = float(input("What formula would you like to use?  "))
    
    if x == 1:
        print "Speed formula"
        d = float(input("What is the distance?(m)  "))
        t = float(input("what is the time?(s) "))
        v = (d/t)
        print "The velocity is", v
        
    elif x == 2:
        print "Acceleration formula"
        vf = float(input("What is the velocity final?(m/s)  "))
        vi = float(input("what is the velocity initial?(m/s)  "))
        t = float(input("What is the time?(s)  "))
        a = (vf-vi)/t
        print "The acceleration is", a
        
    elif x == 3:
        print "Weight formula"
        m = float(input("What is the mass?(Kg)  "))
        g = 9.8
        f = (m*g)
        print "The weight is", f
        
    elif x == 4:
        print "F=ma"
        m = float(input("What is the mass?(Kg)  "))
        a = float(input("what is the acceleration?  "))
        f = (m*a)
        print "The force is", f
        
    elif x == 5:
        print "Momentum formula"
        m = float(input("What is the mass?(Kg)  "))
        v = float(input("What is the velocity?(m/s)  "))
        p = (m*v)
        print "The momentum is", f
        
    elif x == 6:
        print "Mechanical Advantage"
        fi = float(input("What is the force input?(N)  "))
        fo = float(input("What is the force output?(N)  "))
        ma = (fo/fi)
        print "The mechanical advantage is", ma
        
    elif x == 7:
        print "Work formula"
        f = float(input("What is the force?(N)  "))
        d = float(input("What is the distance?(m)  "))
        w = (f*d)
        print "The work done is", w
        
    elif x == 8:
        print "Power formula"
        w = float(input("What is the work?(J)  "))
        t = float(input("What is the time?(s)  "))
        p = (w/t)
        print "The power is", p
        
    elif x == 9:
        print "Interior measures of an n sided regular polygon"
        n = float(input("How many sides on the polygon: "))
        degrees = ((n-2)*180)/n
        print degrees
        if n == 3:
            print "Triangle"
        if n == 4:
            print "Quadrilateral"
        if n == 5:
            print "Pentagon"
        if n == 6:
            print "Hexagon"
        if n == 7:
            print "Heptagon"
        if n == 8:
            print "Octagon"
        if n == 9:
            print "Nonagon"
        if n == 10:
            print "Decagon"
        if n == 11:
            print "Hendecagon"
        if n == 12:
            print "Dodecagon"
        if n == 13:
            print "Tridecagon"
        if n == 14:
            print "Tetradecagon"
        if n == 15:
            print "Pentadecagon"
        if n == 16:
            print "Hexadecagon"
        if n == 17:
            print "Heptadecagon"
        if n == 18:
            print "Octadecagon"
        if n == 19:
            print "Nonadecagon"
        if n == 20:
            print "Icosagon"
            
    elif x == 10:
        print "Pythagorean Theorem"
        a = float(input("What is the length of A:  "))
        b = float(input("What is the length of B:  "))
        c = (a*a) + (b*b)
        c = c**0.5
        print c
        
    elif x == 11:
        print "Area of a Circle"
        r = float(input("What is the radius?  "))
        p = 3.14
        a = p*r*r
        print "The area is", a
        
    elif x == 12:
        print "Area of a Quad."
        b = float(input("What is the base length?  "))
        h = float(input("What is the height length?  "))
        a = (b*h)
        print "The area is", a
        
    elif x == 13:
        print "Area of a Trapazoid"
        b1 = float(input("What is the bottom base length?  "))
        b2 = float(input("What is the top base length?  "))
        h = float(input("What is the height length?  "))
        a = ((b1+b2)*h)/2)
        print "The area is", a
    
    elif x == 14:
        print "Area of a Triangle"
        b = float(input("What is the base length?  "))
        h = float(input("What is the height length?  "))
        a = (b/2)*h
        print "The area is", a
        
    else x == 15:
        print "Area of a Rhombus/Kite"
        d1 = float(input("What is the length of the larger diagonal?  "))
        d2 = float(input("What is the length of the smaller diagonal?  "))
        a = (d1*d2)/2
        print "The area is", a
    Normally the menu lines up, it is not a problem.
  • Smygis
    New Member
    • Jun 2007
    • 126

    #2
    One misstake you have made (I havent run any of the code, And i wont cuz im in a hurry).

    Code:
    else x == 15:
    Else is not suposed to have any boolean statments. Replace it with someting like this:

    [code=python]
    elif x == 15:
    #youre code here.

    else:
    print "Numer %d not in range." % x[/code]

    Comment

    • jlm699
      Contributor
      • Jul 2007
      • 314

      #3
      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

      Comment

      • SpennH
        New Member
        • Apr 2008
        • 3

        #4
        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?

        Comment

        • bvdet
          Recognized Expert Specialist
          • Oct 2006
          • 2851

          #5
          Something like this:
          [code=Python]
          while True:
          print "Formulas"
          print "--------------------------------------------"
          ............... .....
          print " | 16.Exit |
          print "--------------------------------------------"

          x = int(raw_input(" What formula would you like to use? "))

          if x == 1:
          .......
          if x == 16:
          break[/code]I suggest using raw_input, which always returns a string. If you create a function for your code, you can substitute return for break.

          Comment

          • SpennH
            New Member
            • Apr 2008
            • 3

            #6
            Thanks, it worked perfectly!

            Comment

            Working...