Blue Bridge Cup Daily One Question (2): Wiener Guess the Age (python)

Topic:

The American mathematician N. Wiener was precocious and went to college at the age of 11. He was invited to give lectures at Tsinghua University in China from 1935 to 1936.
Once, he attended an important meeting and his young face was eye-catching. So someone asked about his age, and he replied:
"The cube of my age is a 4-digit number. The fourth power of my age is a 6-digit number. These 10 digits happen to contain 10 digits from 0 to 9, each Both appeared exactly once."
Please calculate how young he was at that time.

Solution:

Using the inverse solution
, the third power of 10 is a 4-digit number and
the third power of 30 is a five-digit number.
So Wiener’s age is between 10 and 30. Make
a one-by-one comparison.
First, create a list containing 0-9 and try
starting from 10.
For each query to the third and fourth powers of the
age, each digit of the age is compared with 0-9
, and the result of each comparison is deleted.
If the final list is empty, delete all from 0-9,
then this age is Wiener Age at that time

Code:

for i in range(10, 30):
    number = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    age_1 = list(str(i ** 3))
    age_2 = list(str(i ** 4))

    for j in age_1:
        try:
            number.remove(int(j))
        except:
            pass
        else:
            pass

    for y in age_2:
        try:
            number.remove(int(y))
        except:
            pass
        else:
            pass

    if not number:
        print(i)
        break

Answer:
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_50791900/article/details/112312490