Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # and pwr, such that 0<pwr<6 and root^pwr is equal to the integer entered by
- # the user. If no such pair of integers exists, it should print a message to
- # that effect.
- rawUserNum = int(raw_input('Enter an integer: '))
- userNum = abs(rawUserNum)
- root = 0
- pwr = 5
- i = root
- while i < userNum:
- j = pwr
- while j > 0:
- if i ** j == userNum:
- root = i
- pwr = j
- i = userNum
- break
- j -= 1
- i += 1
- if root ** pwr == userNum:
- print ''
- print 'User entered:', userNum
- if rawUserNum < 0:
- print 'root is:', -root
- print 'pwr is:', pwr
- print str(-root) + '^' + str(pwr) + ' = ' + str(-root ** pwr) + \
- ', which is equal to the integer the user entered.'
- else:
- print 'root is:', root
- print 'pwr is:', pwr
- print str(root) + '^' + str(pwr) + ' = ' + str(root ** pwr) + \
- ', which is equal to the integer the user entered.'
- else:
- print 'No such pair of integers exist, such that: 0<pwr<6 and root^pwr' \
- ' is equal to the integer enetered by the user.'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement