dimanche 17 octobre 2021

How to format the Else Statement

I want to create a program, that the user gives an integer. and then the program prints two integers, the root and power of that number, such that root ** power is equal to the integer entered by the user. And the program looks for the lowest power for which root ** power is desired. and if no power or root exists it outputs that "no integer exists"

here is my code so far:

x = int(input("Enter an interger: "))

    root = 0
    pwr = [ ]
    while root < abs(x):
        root += 1
        for pwr in range(2,7,1):
            break
        z = min(str(pwr))
        y = int(z)


            
        if root ** (y) == (x):
            # if x < 0:
            #     print(root, "**", y, "=", x)
            if root > 0 or y == int:
                print(root, "**", y, "=", x)
            else:
                print("No such integer exists")

My problem is that my else statement is not working. for example, output if integer is 66

Enter an integer: 66
None

However, it should output "No such integer exist"

Aucun commentaire:

Enregistrer un commentaire