Python学习笔记0002:判断正负数

来源:互联网 发布:最大的淘宝客网站 编辑:程序博客网 时间:2024/04/30 09:30
[python] view plain copy
  1. #!/usr/bin/env python  
  2. # -*- coding: UTF-8 -*-  
  3. #  
  4. # Copyright [Gtlions Lai].  
  5. # Create Date:  
  6. # Update Date:  
  7. __authors__ = '"Gtlions Lai" <gtlions.l@qq.com>'  
  8.   
  9. """判断正负数. 
  10.  
  11. 主要功能描述. 
  12.  
  13.   ClassFoo: 类概述. 
  14.   functionBar(): 函数概述. 
  15. """  
  16. import re  
  17. import string  
  18.   
  19.   
  20. num = '^[-+]{0,1}[0-9]{1,}.{0,1}[0-9]{0,}'  
  21. check = True  
  22. while check:  
  23.     input = raw_input("请输入一个数值:")  
  24.     if len(input) == 0 or not re.findall(num,input):  
  25.         print "程序退出!"  
  26.         break  
  27.     inputnew = string.atof(input)  
  28.     if inputnew > 0 or inputnew < 0:  
  29.         if inputnew > 0:  
  30.             print input , "是正数!"  
  31.         if inputnew < 0:  
  32.             print input , "是负数!"  
  33.     else:  
  34.         print "输入的是0,既不是正数也不是复数!"  

-EOF-
1 0