Python Forum

Full Version: X value?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm relatively new to Python 2 and can't figure out how to do an 'X' value (a number that could be anything). A few days ago I noticed 4 is 2 squared and 2+2. Then I wondered: is 4 the only number that has this characteristhic? I tried to make a code so that I could make sure of it, but I needed an 'X' value that I couldn't get. Can someone help me with this?
Quote:is 4 the only number that has this characteristhic?
Yep.

def chech_num(n):
    if n**n == n + n:
        return 'Ok!'
    else:
        return 'Fail!'


n = float(input('Number: ')) / 2
print(chech_num(n))
To auto check, you can loop through a range of numbers.