title: how to convert python code in to function
body: <p>I am learning python by my self. i write this code. I try to convert this python code in function by using main. I do know how to do it. can someone help me with it. I did try for more than 3 hrs. now my mind is stop working. I will really appreciated your help. </p>
  
  <p>isExit = 0 </p>
  
  <p>count = 0 </p>
  
  <p>total_int = 0 </p>
  
  <p>while True: </p>
  
  <pre><code>total_int = 0
  
  count = 0
  
  print ("\n")
  
  print ("1) Credit Card Payoff Summary")
  
  print ("2) Credit Card Payoff Details")
  
  print ("3) Exit ")
  
  choice = (int)(input("Enter your choice - "))
  
  if(choice == 1):
  
      balance = (float)(input("Enter your credit card balance - "))
  
      apr = (float)(input("Enter Annual Percentage Rate - "))
  
      print ("1) Interest on current balance + 1% of current balance.")
  
      print ("2) 2% of current balance.")
  
      select = (int)(input("Select your choice - "))
  
      if(select == 1):
  
          if(balance &lt;= 0 or apr &lt;= 0) : #checking if balance or APR is 0 or not
  
              print ("Interest cannot be calculated as balance or APR is 0.")
  
          else :
  
              while (balance &gt; 0) :
  
                  m_interest = float(balance) * (apr/ 1200)
  
                  min_month_pay = m_interest + (0.01 * balance)
  
                  if (min_month_pay &lt; 15):
  
                      min_month_pay = 15
  
                  principal_paid = min_month_pay - m_interest
  
                  balance = balance - principal_paid
  
                  total_int += m_interest
  
                  count += 1
  
              years = (float)(count / 12)
  
              print ("Years required to payoff card : ", round(years, 2)) #round() is used to format the float number upto 2 decimal place.
  
              print ("Total interest paid : ", round(total_int,2))
  
  elif(select == 2):
  
      if(balance &lt;= 0 or apr &lt;= 0) :
  
          print ("Interest cannot be calculated as balance or APR is 0.")
  
      else :
  
          while (balance &gt; 0) :
  
              m_interest = float(balance) * (apr/ 1200)
  
              min_month_pay = 0.02 * balance
  
              if (min_month_pay &lt; 15):
  
                  min_month_pay = 15
  
              principal_paid = min_month_pay - m_interest
  
              balance = balance - principal_paid
  
              total_int += m_interest
  
              count += 1
  
          years = (float)(count / 12)
  
          print ("Years required to payoff card : ", round(years, 2))
  
          print ("Total interest paid : ", round(total_int, 2))
  
  else :
  
      print ("Invalid selection.")
      if(choice == 2):
          balance = (float)(input("Enter your credit card balance - "))
  
          apr = (float)(input("Enter Annual Percentage Rate - "))
  
      print ("1) Interest on current balance + 1% of current balance.")
  
      print ("2) 2% of current balance.")
  
      select = (int)(input("Select your choice - "))
  
      if(select == 1):
  
          if(balance &lt;= 0 or apr &lt;= 0) :
  
              print ("Interest cannot be calculated as balance or APR is 0.")
  
          else :
  
              print ("Month Min. Int. Princ. Rem. Pay. Paid Paid Bal.") #headers of the detail
  
              while (balance &gt; 0) :
  
                  m_interest = float(balance) * (apr/ 1200)
  
                  min_month_pay = m_interest + (0.01 * balance)
  
                  if (min_month_pay &lt; 15):
  
                      min_month_pay = 15
  
                  principal_paid = min_month_pay - m_interest
  
                  balance = balance - principal_paid
  
                  total_int += m_interest
  
                  count += 1
  
                  print (count, " ", round(min_month_pay, 2), " ", round(m_interest, 2), " ", round(principal_paid, 2), " ", round(balance, 2)) #This will print the detail line by line
  
              years = (float)(count / 12)
  
              print ("Years required to payoff card : ", round(years, 2))
  
              print ("Total interest paid : ", round(total_int, 2))
  
  if(select == 2):
  
      if(balance &lt;= 0 or apr &lt;= 0) :
  
          print ("Interest cannot be calculated as balance or APR is 0.")
  
      else :
  
          print ("Month Min. Int. Princ. Rem. Pay. Paid Paid Bal.")
  
          while (balance &gt; 0) :
  
              m_interest = float(balance) * (apr/ 1200)
  
              min_month_pay = 0.02 * balance
  
              if (min_month_pay &lt; 15):
  
                  min_month_pay = 15
  
              principal_paid = min_month_pay - m_interest
  
              balance = balance - principal_paid
  
              total_int += m_interest
  
              count += 1
  
              print (count, " ", round(min_month_pay, 2), " ", round(m_interest, 2), " ", round(principal_paid, 2), " ", round(balance, 2))
  
          years = (float)(count / 12)
  
          print ("Years required to payoff card : ", round(years, 2))
  
          print ("Total interest paid : ", round(total_int, 2))
  
  else :
  
          print ("Invalid selection.")
  
  if (choice == 3):
  
          print ("Application is terminating now.")
  
          isExit = 1
  
  else:
  
          print ("Invalid Choice.")
  
  if(isExit):
  
      break
  </code></pre>