What's Wrong With Such A Simple Code?

Discussion in 'Python' started by bsmile, Aug 15, 2011.

  1. bsmile


    Aug 15, 2011
    Likes Received:
    I am totally new to python, I wrote such a simple code, as

    in file ggg.py I wrote

    var = raw_input("Enter something: ")
    print "you entered ", var

    under linux shell, I issue
    python ggg.py

    it complains

    File "ggg.py", line 1
    var = raw_input("Enter something: ")
    SyntaxError: invalid syntax

    any idea what goes wrong?
    bsmile, Aug 15, 2011
    1. Advertisements

  2. bsmile


    Jun 28, 2017
    Likes Received:
    What version of Python are you using?
    Python 2.x has the raw_input() function, but that was done away with in
    Python 3.x.
    In Python 3.x your code would be:

    var = input("Enter something: ")
    print ("you entered ", var)

    Note the () in the print function.
    this happens when you have Python run your program from a command line.
    You are getting a version 3 Python interpreter.
    UoPTucson, Jul 3, 2017
    Ian likes this.
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.