1. 程式人生 > >python3 練習題100例 (三)

python3 練習題100例 (三)

題目三:一個整數,它加上100後是一個完全平方數,再加上168又是一個完全平方數,請問該數是多少?

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

""" 題目三:一個整數,它加上100後是一個完全平方數,再加上168又是一個完全平方數,請問該數是多少?"""

__author__ = 'Fan Lijun'

import math

for x in range(10000):
    if math.sqrt(x + 100) == int(math.sqrt(x + 100)) and math.sqrt(x + 100 + 168) == int(math.sqrt(x + 100 + 168)):
        print(f'{x}是一個完全平方數。')

for y in range(0, -100, -1):
    if math.sqrt(y + 100) == int(math.sqrt(y + 100)) and math.sqrt(y + 100 + 168) == int(math.sqrt(y + 100 + 168)):
        print(f'{y}是一個完全平方數。')