Write a program that asks the user to enter an integer N and prints two integers, root and power, such that 1 < power < 6 and... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Write a program that asks the user to enter an integer N and prints two integers, root and power, such that 1 < power < 6 and...

Write a program that asks the user to enter an integer N and prints two integers, root and power, such that 1 < power < 6 and N = root ** power. If no such pair of integers exists, it should print a message to that effect. There are two loops, one for power and one for root. Order the loops so that if N = 64, then your program find that N = 8 ** 2 rather than N = 4 ** 3.That is, order the loops so that the lowest power is found. N = int(input('Please entre an integer: ')) pwr=2 root = 0 for pwr in range(1,5): if root**pwr != N: root+=1 else: print ("root:", root, "power:", pwr) Why isn't this code working?

8th Oct 2020, 1:10 AM
Ali Rezaei
Ali Rezaei - avatar
1 Answer
0
try this N = int(input('Please entre an integer: ')) found =False for pwr in range(2,6): for root in range(0,N): if root**pwr == N: print ("root:", root, "power:", pwr) found=True break else: continue break if found==False: print('Not found!')
8th Oct 2020, 2:11 AM
Ruba Kh
Ruba Kh - avatar