While loop - PYTHON

original = "Hello"

answer = "yes"
while answer == "yes":
          if len(original) > 0:
           answer = raw_input("do you want to continue? type 'yes' for yes, otherwise 'no' ")

Is this correct?


All the indentation is correct (I don’t know why it is not showing up here)


correct for what? An exercise?

you need to use format, see FAQ.

else: and the last line of your program don’t seem to have same indent level, seems one space difference.


I am using the format. I don’t know why it’s not showing up here.
And correct in the sense, the logic. In general.


I will check the one space difference, thankyou! That might be what is preventing it from giving an output.


you didn’t, see here:

Quick Tips for Writing Good Posts

the program doesn’t do much, it just prints Hello as long as the user enters yes. But logic wise this is correct, after fixing the indent error

Did you code this in the codecademy lesson? If not, i would recommend setting your editor to 4 spaces soft tabs.


I will check the one space difference thing, thankyou!


Thank you! The problem got solved. I had not put proper indentation for the “Do you want to continue?” line.


For python i would personally recommend soft tabs, meaning that when the tab key is pressed, the editor insert 4 spaces (4 spaces is generally recommend). The opposite is hard tabs, which insert a tab character.

You can’t change this in the codecademy editor, but if you work outside codecademy, its highly recommend to look for this setting in your editor


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.