1

I'm just starting to learn Python using a raspberry pi. One of the exercises on the pi website has the following code:

for i in range(2):
    print("A")
print("B")

Which the tutorial says should give the output:

A
A
B

However, when I run this code in the Python 3.5.3 IDLE, I get a syntax error, with the second "print" highlighted. Any thoughts? Here is the website I'm referring to:

https://www.raspberrypi.org/documentation/usage/python/

juanpa.arrivillaga
  • 88,713
  • 10
  • 131
  • 172
KPyke
  • 33
  • 3
  • 1
    You have to hit Enter again after the first `print`, let that run, *then* paste in the second `print` separately, if you're in an interactive session. – jonrsharpe Dec 23 '17 at 21:26
  • I just copy pasted the code from above and it works fine – Ivan86 Dec 23 '17 at 21:27

1 Answers1

-1

I believe the the second print should be indented as well because python relies on white space instead of parenthesis or brackets, so the second print isnt being counted, however, im not super great at python

  • Indeed, you are not that good at Python... Correct: Python's blocks are determined by indentations. But consider what happens when the second line is indented as well, as you suggest. That puts it inside the same block as the line above. This would make the output `A B A B` (each letter on a separate line), still not what the OP's tutorial says it would be. – Jongware Dec 23 '17 at 22:13