title: Implementing long division using a generator function in python
body: <p>As an exercise to try to understand generator functions I am trying to write a function that simulates long division and returns the number one digit at a time. I have written this function and it doesn't seem to work. However if I step through it line by line in the shell it does exactly what I want it to do so I'm not sure what to do going forward. I've read through posts on the internet about generator functions here: </p>
  
  <p>and from what I understand I just replace the return statement with a yield statement. Is this not the case? Can anybody please tell me what I am doing wrong? Any help is appreciated.</p>
  
  <pre><code>def decimals(number):    
      """
      Takes a numnber and generates the digits of  1/n.
  
      """
      divisor = number
      dividend = 1
  
  
      while dividend % divisor != 0:
          #Floor division is the // operator        
          quotient = divisor // dividend
          remainder = dividend % divisor
  
          temp = quotient * divisor
          if remainder != 0 :
              temp = quotient * divisor
  
          if temp &gt; dividend:
              dividend = dividend * 10
              dividend = dividend - temp
          else:
              dividend = dividend - temp
          yield quotient
  
  
  
  def main():
      gen = decimals(4)
      print(next(gen))
  
  if __name__ == "__main__":
      main()
  </code></pre>