python - How do i return to the beginning of my code/have a nested loop? -


i want code run if condition not met (in if loop) return beginning of code, asking user input sentence. how add nested loop (if it's called)?

sentence = input("please input sentence: ") word = input("please input word: ") sentence = sentence.lower() word = word.lower() wordlist = sentence.split(' ') print ("your word, {0}, in positions:".format (word)) position,w in enumerate(wordlist):     if w == word:         print("{0}".format(position+1)) 

you can put while loop around code , break or continue depending on input:

while true:      sentence = input("please input sentence: ")      if bad(sentence): # replace actual condition          continue      ...      position, w in enumerate(wordlist):          ...      break 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -