[Tutor] beginning to code

Alan Gauld alan.gauld at yahoo.co.uk
Sun Sep 10 14:54:50 EDT 2017


For some reaspon I'm missing the original post so apologies
to replying to Senthil instead of the OP directly...


>> 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 ()
>>
>> But everytime this produces an error (unindent does not match any outer
>> indention level) in the "print ('hi, joe. Pwd?')" sentence.

Its best when posting to the group to include the full error
text rather than summarizing it. In this case we don't need
it but in other cases the extra detail may be important.

The error is telling you that the indentation of that line
is wrong. Indentation, or spacing, is very important in
Python - much more so than in other languages. Python uses
the spacing to tell which lines are grouped together.

In your code Python can't tell whether the print line is
supposed to be inside the if block along with the continue
statement or outside the if block and following the if statement.

You need to align the print (and all subsequent lines)
with the if.

One question though. As written, your code only goes
past the if statement if the input name is *bert*.
Why then does the welcome say Hi *joe*????

Just a thought...


-- 
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




More information about the Tutor mailing list