#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    9
    Rep Power
    0

    Value=input("Enter a value") problem


    helllo everyone, I am quite new to Python and am currently using Python 3.3. I got stuck with the following problem. Is there anyone who can provide me with guidelines/help on the following problem?

    >>>value=input("Enter a value ")
    >>>Enter a value 9*9
    >>>inval
    >>>'9*9'

    the code above should print out the result of multiplication as value being referenced by the inval , but instead '9*9' is printed out. Is there any problem with my coding? Greatly any help/ guideline that can be provided.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    114
    Rep Power
    4
    input() changed between Python 2 and 3 -- Python 3's input() is equivalent to Python 2's raw_input(). If you want your input to be evaluated in Python 3, you need to explicitly call eval() on it.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    9
    Rep Power
    0
    Originally Posted by Nyktos
    input() changed between Python 2 and 3 -- Python 3's input() is equivalent to Python 2's raw_input(). If you want your input to be evaluated in Python 3, you need to explicitly call eval() on it.
    hello, thanks for your quick reply. But, can you show me how to explicitly call eval().

    Is it like this:
    value=eval("Enter a value")? or
    value=raw_input("Enter a value")?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    114
    Rep Power
    4
    The concise way would be like this:
    Code:
    value = eval(input())
    raw_input() doesn't exist in Python 3.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    9
    Rep Power
    0

    It works!! thanks. :)


    Originally Posted by Nyktos
    The concise way would be like this:
    Code:
    value = eval(input())
    raw_input() doesn't exist in Python 3.
    yeap, it works, thank you very much for your help.

IMN logo majestic logo threadwatch logo seochat tools logo