Python Practice Example 46
Title:Find the square of the input number. If the square is less than 50, exit.
Program analysis:None
Program source code:
Example
#!/usr/bin/python
# -*- coding: UTF-8 -*-
TRUE = 1
FALSE = 0
def SQ(x):
return x * x
print ('If the input number is less than 50, the program will stop running.')
again = 1
while again:
num = int(input('Please enter a number:'))
print ('The result is: %d' % (SQ(num)))
if SQ(num) >= 50:
again = TRUE
else:
again = FALSE
The output of the above example is:
如果输入的数字小于 50,程序将停止运行。 请输入一个数字:12 运算结果为: 144 请输入一个数字:14 运算结果为: 196 请输入一个数字:1 运算结果为: 1Other extensions
Python 100 Examples