Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 25th, 2013  |  syntax: None  |  size: 1.58 KB  |  views: 68  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ## This program is Finger Exercise 3.1, Introduction to Computation and Programming Using Python.
  2.  
  3. print 'Given an integer, this program will return two integers, root and pwr, for 0 < pwr < 6, such that integer=root^pwr.'
  4.  
  5. integer = int(raw_input('Enter an integer.'))
  6.  
  7. print 'For integer ' + str(integer) + ', root = ' + str(integer) + ' and pwr = 1.'
  8.  
  9. if integer>=0:
  10.     Root2 = -1
  11.     while Root2<integer:
  12.         Root2 = Root2 + 1        
  13.         if Root2**2==integer:
  14.             print 'For integer ' + str(integer) + ', root = ' +str(Root2) + ' and pwr = 2.'
  15.  
  16. if True:
  17.     Root3 = -1
  18.     while Root3<abs(integer):
  19.         Root3 = Root3 + 1
  20.         if Root3**3==abs(integer):
  21.             if integer>=0:
  22.                 print 'For integer ' + str(integer) + ', root = ' + str(Root3) + ' and pwr = 3.'
  23.             elif integer<0:
  24.                 NegRoot3 = -Root3
  25.                 print 'For integer ' + str(integer) + ', root = ' + str(NegRoot3) + ' and pwr = 3.'
  26.  
  27. if integer>=0:
  28.     Root4 = -1
  29.     while Root4<integer:
  30.         Root4 = Root4 + 1
  31.         if Root4**4==integer:
  32.             print 'For integer ' + str(integer) + ', root = ' + str(Root4) + ' and pwr = 4.'
  33.  
  34. if True:
  35.     Root5 = -1
  36.     while Root5<abs(integer):
  37.         Root5 = Root5 + 1
  38.         if Root5**5==abs(integer):
  39.             if integer>=0:
  40.                 print 'For integer ' + str(integer) + ', root = ' + str(Root5) + ' and pwr = 5.'
  41.             elif integer<0:
  42.                 NegRoot5 = -Root5
  43.                 print 'For integer ' + str(integer) + ', root = ' + str(NegRoot5) + ' and pwr = 5.'
clone this paste RAW Paste Data