我用python实现做此题,代码如下:
__author__ = 'Administrator'number = raw_input("Please input a number:")listnumber = list(str(number))if "." in listnumber: locate = listnumber.index(".") integer = listnumber[:locate] integeritem = ''.join(integer) print "The number you inputed is:"+number print "The integer is:"+integeritem float = listnumber[locate+1:] floatitem = ''.join(float) print "The float is:"+floatitemelse: print "The number is an integer,is:"+number
总结:1.要灵活使用int(),str()等转换类型。 2.修复了一个问题:第十行如果没有“locate+1”,当输出floatitem时,会把小数点输出来。