title: Collatz Sequence. (Python 3)
body: <p>I've started the book <a href="https://automatetheboringstuff.com/chapter3/" rel="nofollow">"Automate The Boring Stuff" by Al Sweigart</a>. </p>
  
  <p>At the end of Chapter 3, the author suggests creating a Collatz Sequence in Python as a practice exercise. (the practice exercise suggests I use a the print function and return statement)</p>
  
  <p>When I use a <code>print()</code> function in my code, it works great and I get all the evaluated values I want to see on the screen:</p>
  
  <pre><code>print("This is The Collatz Sequence")
  user = int(input("Enter a number: "))
  
  
  def collatz(n):
      print(n)
      while n != 1:
          if n % 2 == 0:
              n = n // 2
              print(n)
          else:
              n = n * 3 + 1
              print(n)
  
  
  collatz(user)
  </code></pre>
  
  <p><strong>Question:</strong><br>
  How come when I want to use the <code>return</code> statement, the <code>while</code> loop only runs once?</p>
  
  <p>For example, passing the integer 3 into my function with the <code>return</code> statement only gives me the <code>return</code> value of 3 and 10:</p>
  
  <pre><code>print("This is The Collatz Sequence")
  user = int(input("Enter a number: "))
  
  
  def collatz(n):
      print(n)
      while n != 1:
          if n % 2 == 0:
              n = n // 2
              return n
          else:
              n = n * 3 + 1
              return n
  
  
  result = collatz(user)
  print(result)
  </code></pre>