-4

I am a beginner so I am sure this is mundane. I am following a beginner's exercise and I typed the code correctly and check and recheck the copy I typed but it doesn't look like what the exercise should look like. Two lines should appear in the output, but only one of them appears. I will include what I type in Atom below and what the code should look like. I am working at following "Learn Python the Hard Way" and this is one of the exercises. I am using a Macbook with Atom as my editor. Notice how only one of the sentences appears in my finished results?

The code I entered in Atom:

# A comment, this is so you can read your program later.
# Anything after the # is ignored by python.

print "I could have code like this." # and the coment after is ignored

# You can also use a comment to "disable" or comment out a piece of code:
 # print "This won't run."

 print "This will run."

What the code should do if written properly:

$ python ex2.py
I could have code like this.
This will run.

This is what I see when I go to my terminal:

IndentationError: unexpected indent
Renays-MacBook-Pro:mystuff3 renayjohnson$ python ex2.py
  File "ex2.py", line 9
    print "This will run."
    ^
IndentationError: unexpected indent
Renays-MacBook-Pro:mystuff3 renayjohnson$ 
David Z
  • 128,184
  • 27
  • 255
  • 279
naysjp
  • 3
  • 2
  • 2
    Consider reading the error message carefully – Mad Physicist Jan 08 '17 at 04:53
  • 1
    if you are still confused at that point, search for the message on Google. – Mad Physicist Jan 08 '17 at 04:54
  • You have an extra space, before your second `print` statement, delete it. – Burhan Khalid Jan 08 '17 at 04:55
  • Possible duplicate of [Indentation Error in Python](http://stackoverflow.com/questions/14979224/indentation-error-in-python) – Mad Physicist Jan 08 '17 at 04:57
  • 2
    Please get in the habit of a) reading and attempting to understand error messages b) exhausting all readily available resources before posting a question. – Mad Physicist Jan 08 '17 at 04:59
  • Well Mad Physicist, I am sorry this is mundane to you and I did apologize in the beginning. It's a bit hard to know what you don't know when you are just starting. I went through the copy and made sure there were no typo errors but noticed that there was still a sentence missing and I did search to see if I could find help but again, it's hard to know what to look for when you don't know. Sir, if it pains you to answer questions, I am sure someone else will answer. This community was suggested to me as a resource. I thank all that took time to answer my question and I appreciate the input. – naysjp Jan 08 '17 at 06:39
  • @naysjp. While I may sound curt, the advice I am giving you is quite valuable. We were all beginners at some point, and I can certainly remember myself being as confused by a mundane error as I imagine you were when you asked this question. What sets the experts apart from the beginners is not so much knowledge of the language but more familiarity and level of comfort in using the available resources. I did not mark your question as a duplicate to make your life harder. I did it to show you the first place I'd recommend looking so you could learn to do the same. – Mad Physicist Jan 08 '17 at 19:16

1 Answers1

0

At line 9, the print line is indented with a space. Just remove that space character and rerun your script. Also, looking at the original source of your exercise, there is no indentation in that line. It's worth-mentioning that comment lines are indented at the same level of the code that follows them. In your code at line 7, the block comment line shouldn't be indented as well but it isn't raising any error in that comment line.

However, you should read about the Off-side rule and how such programming languages are expressed by their indentation.

0xack13
  • 462
  • 4
  • 8