python怎么进行小数的四则运算?并且可以自己定义小数点位数?我现在只会整数的四则运算,如下:a= int(raw_input('please input number1:'))b= int(raw_input('please input number2:'))print "the + of the result is:%s\n\the -

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/06 01:45:38
python怎么进行小数的四则运算?并且可以自己定义小数点位数?我现在只会整数的四则运算,如下:a= int(raw_input('please input number1:'))b= int(raw_input('please input number2:'))print

python怎么进行小数的四则运算?并且可以自己定义小数点位数?我现在只会整数的四则运算,如下:a= int(raw_input('please input number1:'))b= int(raw_input('please input number2:'))print "the + of the result is:%s\n\the -
python怎么进行小数的四则运算?并且可以自己定义小数点位数?
我现在只会整数的四则运算,如下:
a= int(raw_input('please input number1:'))
b= int(raw_input('please input number2:'))
print "the + of the result is:%s\n\
the - of the result is:%s\n\
the * of the result is:%s\n\
the / of the result is:%s"%(a+b,a-b,a*b,a/b)
因为int是整数,我不知道怎么进行小数的运算,求教!

python怎么进行小数的四则运算?并且可以自己定义小数点位数?我现在只会整数的四则运算,如下:a= int(raw_input('please input number1:'))b= int(raw_input('please input number2:'))print "the + of the result is:%s\n\the -
什么意思? 你将a 、b定义为float型不就可以了吗?
fromat()比%格式化输出强悍,最好学会用format格式化:
如保留2位小数:'{0:0.2}.format(1.2/7) ===0.17