Hello kerbi! On Sun, Sep 10, 2017 at 6:32 AM, Elmar Klein <geoke...@gmx.at> wrote: > Hi there, > > im starting to learn how to code (bougt me the "automate the boring stuff > with phyton" book). > > And im not going anywhere with a code sample using the "continue" statement. > > The code i should try is as following: > > while True: > print ('who are you') > name = input () > if name != 'bert': > continue > print ('hi, joe. pwd?') > pwd = input () > if pwd == 'sword': > break > print ('access granted') > > But everytime this produces an error (unindent does not match any outer > indention level) in the "print ('hi, joe. Pwd?')" sentence.
As the others have said your indentation is inconsistent. "print ('who are you')" is indented 6 spaces under "while True:". But "continue" is indented 8 spaces under "if name != 'bert':". And "print ('hi, joe. pwd?')" is indented 2 spaces under "if name != 'bert':" when it should not be indented at all! You might want to review pages 37-38 where the author talks about "Blocks of Code" and make sure you are *getting it*. If not, come back with specific questions. Senthil mentioned using a proper programmer's editor that supports Python syntax. This can make things much easier. Generally speaking, you wish a single level of indentation to always be the same number of spaces. The commonly used number is one indentation level equals 4 spaces. Most editors will allow you to use the <Tab> key to indent, converting it to 4 spaces (Or a different number if you configure your <Tab> differently in the editor.). A side note: Don't mix tabs with spaces! Ensure that your editor converts tabs to spaces. Otherwise you can have a real mess! So look carefully on page 51 of your book where I found the code you are playing with. It looks like you are playing around with modifying it, which is a good thing to do. But you still must maintain the proper block structure of the author's code that you are modifying if you want to accomplish the kinds of things the author is doing. Pay particular to the vertical alignment of each line's contents. For instance, the "w" in "while True:" lines up with the "p" in "print('Access granted.')", which is the last line of the text's code example. Everything else between the first and last lines is indented one or more levels and belongs to the while loop's execution responsibilities. When you look at the while loop's block contents you notice additional levels of indentation belonging to the two if statements. Again notice how these additional levels of indentation define the blocks belonging to each if statement's responsibilities. Another thing is that if I have found the correct page of the code you are trying out, you are being rather free with how you match capitalization with the author's code. This won't matter a whole lot for strings you are printing to screen, but if you start being sloppy with capitalization with Python keywords or identifiers/variable names, then you will soon come to a lot of grief! Also, you add extra spaces to the print() functions. Fortunately this does not matter here, but it shows that you are being a bit cavalier with how you re-type code. This lack of attention to seemingly teeny-tiny details can cause you much grief, such as in your indentation problems. Whereas a human being can usually easily interpret your intentions, computers, being extremely literal in their interpretation of what is typed, might easily not get your intentions. Be careful what you type! It might be educational for you to take your current code with its inconsistent indentation and correct it line by line, but re-running the code after each such correction to see what exactly happens and what new error tracebacks you get. Hope this helps! -- boB _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor