Python Practice Example 100 Example-3

☞☞☞ Click to see more outstanding Python blog ☜☜☜

Python includes exercises 3

Title: An integer that after 268 plus 100 plus and is a perfect square, what is the number is how much?

Program Analysis : Analyzing less than 10,000, then 100 plus the number of prescription, and then prescribing plus 268, if the result of the square root satisfies the following condition, i.e., is the result. See detailed analysis:

Source Code :

#!/usr/bin/python
 # -*- coding: UTF-8 -*- 
 import math 
 for i in range(10000): 
 	#转化为整型值 
 	x = int(math.sqrt(i + 100)) 
 	y = int(math.sqrt(i + 268)) 
 	if(x * x == i + 100) and (y * y == i + 268): 
 		print i 

Examples of the above output is:

21 261 1581

Here Insert Picture Description

Published 111 original articles · won praise 177 · views 210 000 +

Guess you like

Origin blog.csdn.net/qq_45172832/article/details/104847083