Thread: raw_input (???)

    #1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11

    Exclamation raw_input (???)


    I have many scripts that I want to convert to exes but it just does not work because it always says that a EOF Error has come in this script:

    while 1:
    print "calc for a calculator"
    print "fib for the Fibonacci Sequnence"

    a= raw_input("Which option would you like to choose?")

    if a== "calc":
    import Calc
    print Calc

    elif a== "fib":
    import Fibonacci
    print Fibonacci

    in the fifth line by the raw_input("Which option would you like to choose")

    And an other question how do u exit a module but then u can go into it again is it with "reload" but i dont understand.

    please help me
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Hmm, I would like to help you with your raw_input problem only your question doesn't seem to make much sense. Also the line, "in the fifth line by the line "raw_input("Which option would you like to choose")" seems to be randomly placed. Because of this I have no clue what exactly you need help with.
  4. #3
  5. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    You are using the import command to run code in your modules. This is the problem.

    You are right; the only way to re-execute the module would be to use the reload command. But this is not necessary. Normally, code run at import time is only used to configure the module or prepare things for later execution. Your modules need some functions that you can call after the module is imported...

    I suggest you investigate writing functions, you can then do things like:
    Code:
    import fibonacci
    import calc
    
    while True:
        a = raw_input("Type 'calc'' or 'fib' or 'quit'")
        if a not in ['calc','fib','quit']:
            continue
        if a == 'quit':
            break
        if a == 'fib':
            fibonacci.do_fibonacci() # do_fibonacci is a function you write in  the fibonacci module.
        elif a =='calc':
            calc.do_calc() #do_calc is a function in the calc module
    In your calc module you could have a function like this:
    Code:
    def do_calc():
        #the code to do calculations
    I hope this helps

    grim

    p.s. use code tags!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    ya but could you please explian the "def" thingy because i dont understand it
    and please some examples
  8. #5
  9. A wanna-be guru of some sort
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2004
    Location
    Either online or offline
    Posts
    625
    Rep Power
    20
    Originally Posted by monkeyman23555
    ya but could you please explian the "def" thingy because i dont understand it
    and please some examples
    OK
    Code:
      def show(something):
         print something
      
      show("A string")
      A string
      list = [1, 2, 3]
      show(list)
      [1, 2, 3]
    You gotta have parentheses after the function name, even if there are no parameters to the function, gotta have a colon after parentheses, and the body of the function has to be consistently indented.

    Code:
      def multiply(a, b):
         return a*b
      
      
      multiply(2.5, 4)
      10.0
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    hm i get it a bit but wait
    is it just like a thing name and then it just if u type that it asks u for the (a, b)and then it multiplys them like that oh ok thats good i am going to try something and then put the script put here
    thanks
  12. #7
  13. A wanna-be guru of some sort
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2004
    Location
    Either online or offline
    Posts
    625
    Rep Power
    20
    No, this does not ask the user for a, b, but you could make it so
    Code:
      x = input("Please enter the first number: ")
      y = input("Please enter the second number: ")
    And then you can call the multiply(a, b) function like this:
    Code:
    multiply(x, y)
    Am I supposed to sign here?

IMN logo majestic logo threadwatch logo seochat tools logo