Reaper Reaper - 10 months ago 35
Python Question

How to turn my if statement into a while or for loop?

So the program I'm trying to make is that an user can enter a path WHICH HAS TO BE CORRECT to continue. I thought that I would make a simple prompt to tell the user it is either a valid path or not.

This is my prompt code:

if Path.find("Global") == -1:
print "Not a valid path."

Of course I can't use continue in there but I just don't get how to make this prompt as a loop. The idea was that if the Path contains the word "Global" the program continues with another action and if it doesn't contain the word it will tell the user a message and tell the program to stop (break).


Try this:

Path = raw_input("Please enter a valid Path")
while Path.find("Global") == -1:
  print "This is not a valid Path."
  Path = raw_input("Please enter a valid Path")