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

[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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值