Re: [Tutor] Hi Dear!
On Thu, Feb 4, 2016 at 7:49 AM, Alexa kunwrote: > Hi Dear! > I newbie and read 2.1.2. Interactive Mode > https://docs.python.org/3/tutorial/interpreter.html > > but when I type > > >>> the_world_is_flat = True > >>> if the_world_is_flat: > ... print("Be careful not to fall off!") > > I got answer > > IndentationError: expected an indented block > > [root@localhost /]# python3 > Python 3.4.3 (default, Jun 29 2015, 12:15:26) > [GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on linux > Type "help", "copyright", "credits" or "license" for more information. > > >>> the_world_is_flat = True > >>> if the_world_is_flat: > ... print(Be careful not to fall off!) > File "", line 2 > print(Be careful not to fall off!) > ^ > IndentationError: expected an indented block > >>> > There is something funny about your print function. The three periods > indicate that you are no longer in interactive mode. > See my session below > I have installed Python3 in Linux Fedora 23 > Please tell my why Python3 doesn't work? > > Sincerely! > Alexander > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > >>> flat = True >>> if flat: ... print("flat") ... flat >>> -- Joel Goldstick http://joelgoldstick.com/stats/birthdays ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hi Dear!
Hello Alexander, and welcome! My answers are below, between your questions (starting with > quote marks). On Thu, Feb 04, 2016 at 02:49:39PM +0200, Alexa kun wrote: > Hi Dear! > I newbie and read 2.1.2. Interactive Mode > https://docs.python.org/3/tutorial/interpreter.html > > but when I type > > >>> the_world_is_flat = True > >>> if the_world_is_flat: > ... print("Be careful not to fall off!") Look carefully at the last line. Do you notice the indented space between the three dots ... and the print? You need to either press space at least once, or the TAB key, to indent the line. > I got answer > > IndentationError: expected an indented block Here Python tells you exactly what the problem is. Python expected an indented block of text (at least one line, indented by at least one space), but you didn't indent the line. Python expects: if the_world_is_flat: print(Be careful not to fall off!) but you typed: if the_world_is_flat: print(Be careful not to fall off!) without the indentation. You should press the TAB key to indent, or the SPACE key at least once. Also, one last comment: > [root@localhost /]# python3 I see from this that you are running Python as the root superuser. This is VERY dangerous for a beginner (and even for an expert). As root, you can over-write essential system files. Which means that if you accidentally give the wrong Python commands, you could break your system and leave it in a broken state where it needs to be re-installed. It is MUCH safer to experiment as the regular user. If the command prompt shows # then you are running as root. If it shows $ then you are running as a regular user. -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hi Dear!
On 04/02/16 12:49, Alexa kun wrote: > Hi Dear! Hi. Can I ask that in future you choose a subject line that reflects your question? For this case it might be "IndentationError" say. > but when I type > the_world_is_flat = True if the_world_is_flat: > ... print("Be careful not to fall off!") The problem is that is not what you typed. And this is why we always ask for the full error trace - thanks for including it. if the_world_is_flat: > ... print(Be careful not to fall off!) > File "", line 2 > print(Be careful not to fall off!) > ^ > IndentationError: expected an indented block It says that there is an IndentationError which means that Python is expecting to see a line starting in a different place from where it does. In your case that means the line after the 'if' is expected to be "indented". That is it should have a few spaces in front of it (we usually recommend 4 but Python doesn't care so long as there is more than the preceding line). The indentation is Python's way of telling which bits of code need to be executed if the 'if' test is true. Anything that is indented will be executed (or missed if the test is false) as appropriate. The indentation needs to be the same for all the indented lines. ie if foo > 42: print (foo) f = 666 is ok but if foo > 42: print (foo) f00 = 666# not enough spaces won't work. > Please tell my why Python3 doesn't work? It's working just fine, you only need to give it some space(s)... :-) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hi Dear!
On Thu, Feb 4, 2016 at 2:49 PM, Alexa kunwrote: > Hi Dear! > I newbie and read 2.1.2. Interactive Mode > https://docs.python.org/3/tutorial/interpreter.html > > but when I type > > >>> the_world_is_flat = True > >>> if the_world_is_flat: > ... print("Be careful not to fall off!") > > I got answer > > IndentationError: expected an indented block > > [root@localhost /]# python3 > Python 3.4.3 (default, Jun 29 2015, 12:15:26) > [GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on linux > Type "help", "copyright", "credits" or "license" for more information. > > >>> the_world_is_flat = True > >>> if the_world_is_flat: > ... print(Be careful not to fall off!) > File "", line 2 > print(Be careful not to fall off!) > ^ > IndentationError: expected an indented block > >>> > > You should have the print function indented, usually by 4 spaces. This is how Python knows which commands to be executed as part of the if block. So this is what you'll make your code work: >>> the_world_is_flat = True >>> if the_world_is_flat: ... print("Be careful not to fall off!") ... Be careful not to fall off! The interpreter also tries to help you, it puts ... at the begging of the line (instead of >>>) which means it expect some indentation. Emil I have installed Python3 in Linux Fedora 23 > Please tell my why Python3 doesn't work? > > Sincerely! > Alexander > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor