Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
X value?
#1
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?
Reply
#2
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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020