码迷,mamicode.com
首页 > 其他好文 > 详细

判断正负数

时间:2014-09-22 12:27:02      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:io   ar   cti   on   c   new   r   python   as   

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# Copyright [Gtlions Lai].
# Create Date:
# Update Date:
__authors__ = '"Gtlions Lai" <gtlions.l@qq.com>'

"""判断正负数.

主要功能描述.

  ClassFoo: 类概述.
  functionBar(): 函数概述.
"""
import re
import string


num = '^[-+]{0,1}[0-9]{1,}.{0,1}[0-9]{0,}'
check = True
while check:
    input = raw_input("请输入一个数值:")
    if len(input) == 0 or not re.findall(num,input):
        print "程序退出!"
        break
    inputnew = string.atof(input)
    if inputnew > 0 or inputnew < 0:
        if inputnew > 0:
            print input , "是正数!"
        if inputnew < 0:
            print input , "是负数!"
    else:
        print "输入的是0,既不是正数也不是复数!"


-EOF-

判断正负数

标签:io   ar   cti   on   c   new   r   python   as   

原文地址:http://blog.csdn.net/gtlions/article/details/39474313

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!