title: GCD implementation of fraction addition not working properly
body: <p>I am following the Runestone Academy Python3 course and tried to implement 'addition' feature for fractions using Class but I am getting error.</p>
  <p>When I am not using GCD implementation, the code is running fine</p>
  <p>Here is my code:</p>
  <pre><code>class Fraction:
  
      def __init__(self, top, bottom):
          self.num = top
          self.den = bottom
  
      def show(self):
          print(f'{self.num}/{self.den}')
  
      def __str__(self):
          return f'{self.num}/{self.den}'
  
      # adding without GCD implementation
  
      # def __add__(self,other_fraction):
      #     new_num = self.num * other_fraction.den + self.den * other_fraction.num
      #     new_den = self.den * other_fraction.den
  
      #     return Fraction(new_num, new_den)
  
      # adding with GCD implementation
  
      def gcd(self, m, n):
          while m % n != 0:
              m, n = n, m % n
  
          return n
  
      def __add__(self, other_fraction):
          new_num = self.num * other_fraction.den + self.den * other_fraction.num
          new_den = self.den * other_fraction.den
          common = gcd(new_num, new_den)
  
          return Fraction(new_num // common, new_den // common)
  
      # my attempt of adding two fractions by creating a method 'add'
  
      # def add(self,other_fraction):
      #     new_num = self.num * other_fraction.den + self.den * other_fraction.num
      #     new_den = self.den * other_fraction.den
  
      #     return Fraction(new_num, new_den)
  
  
  # my_fraction = Fraction(3,5)
  # print(my_fraction)
  # print(f'I ate {my_fraction} of my pizza')
  # my_fraction.__str__()
  # str(my_fraction)
  
  f1 = Fraction(1, 4)
  f2 = Fraction(1, 2)
  f3 = f1 + f2
  # f3 = f1.add(f2)
  print(f3)
  </code></pre>
  <p>This is the error I am getting:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;D:/Python/Mosh_Lec/app.py&quot;, line 74, in &lt;module&gt;
      f3 = f1 + f2
    File &quot;D:/Python/Mosh_Lec/app.py&quot;, line 53, in __add__
      common = gcd(new_num, new_den)
  NameError: name 'gcd' is not defined
  </code></pre>
  <p>I also tried with this variation but same error:</p>
  <pre><code>    def gcd(self, m, n):
          self.num = m
          self.den = n
          while self.num % self.den != 0:
              self.num, self.den = self.den, self.num % self.den
  
          return self.den
  </code></pre>