Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## This program is Finger Exercise 3.1, Introduction to Computation and Programming Using Python.
- print 'Given an integer, this program will return two integers, root and pwr, for 0 < pwr < 6, such that integer=root^pwr.'
- integer = int(raw_input('Enter an integer.'))
- print 'For integer ' + str(integer) + ', root = ' + str(integer) + ' and pwr = 1.'
- if integer>=0:
- Root2 = -1
- while Root2<integer:
- Root2 = Root2 + 1
- if Root2**2==integer:
- print 'For integer ' + str(integer) + ', root = ' +str(Root2) + ' and pwr = 2.'
- if True:
- Root3 = -1
- while Root3<abs(integer):
- Root3 = Root3 + 1
- if Root3**3==abs(integer):
- if integer>=0:
- print 'For integer ' + str(integer) + ', root = ' + str(Root3) + ' and pwr = 3.'
- elif integer<0:
- NegRoot3 = -Root3
- print 'For integer ' + str(integer) + ', root = ' + str(NegRoot3) + ' and pwr = 3.'
- if integer>=0:
- Root4 = -1
- while Root4<integer:
- Root4 = Root4 + 1
- if Root4**4==integer:
- print 'For integer ' + str(integer) + ', root = ' + str(Root4) + ' and pwr = 4.'
- if True:
- Root5 = -1
- while Root5<abs(integer):
- Root5 = Root5 + 1
- if Root5**5==abs(integer):
- if integer>=0:
- print 'For integer ' + str(integer) + ', root = ' + str(Root5) + ' and pwr = 5.'
- elif integer<0:
- NegRoot5 = -Root5
- print 'For integer ' + str(integer) + ', root = ' + str(NegRoot5) + ' and pwr = 5.'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement