How to create a loop to return to the start of a function python
<p>I am unable to get my <code>while</code> loop to start back at the beginning not to sure what is wrong.</p>

<p>First attempt</p>

<pre><code>def start() :

if choice in weapon:
    print('You have taken the ') + choice + (',this is now in your backpack.\n')  
    inventory.append(choice)

else:
    print("Uh oh, I don't know about that item")

start()  
</code></pre>

<p>second attempt</p>

<pre><code>the_choice = False
while not the_choice:
if choice in weapon:
    print('You have taken the ') + choice + (',this is now in your backpack.\n')  
    inventory.append(choice)
    the_choice = True
     # boom no loop needed 
else:
    print("Uh oh, I don't know about that item")
    the_choice = False  
</code></pre>

<p>I just can't seem to figure it out. </p>

<p>The reason I commented Visual Studio might not be the best python editor is that other editors would have warned you that you did not increase the indentation after your function definition <code>start()</code> in your first attempt, nor did you indent after the start of your <code>while</code> loop in your second attempt. It always helps to include your error messages to help describe your problem, but if I were to guess, you are getting something to the tune of <code>IndentationError</code> messages. </p>

<p>Indentation is one of the most important concepts of python coding and serves the same purpose as curly braces in java or c++. <a href="https://en.wikipedia.org/wiki/Python_syntax_and_semantics#Indentation" rel="nofollow">Wikipedia</a> has a pretty straightforward description of how to do it.</p>

<p>As for editors, I am a personal fan of <a href="https://github.com/spyder-ide/spyder" rel="nofollow">spyder</a> although there are many great ones out there: <a href="https://www.jetbrains.com/pycharm/" rel="nofollow">Pycharm</a>, <a href="http://www.pydev.org/" rel="nofollow">pydev</a>, etc.. </p>

python python-2.7