python怎么进行小数的四则运算?并且可以自己定义小数点位-查字典问答网
分类选择

来自李江的问题

  python怎么进行小数的四则运算?并且可以自己定义小数点位数?我现在只会整数的四则运算,如下:a=int(raw_input('pleaseinputnumber1:'))b=int(raw_input('pleaseinputnumber2:'))print"the+oftheresultis:%snthe-

  python怎么进行小数的四则运算?并且可以自己定义小数点位数?

  我现在只会整数的四则运算,如下:

  a=int(raw_input('pleaseinputnumber1:'))

  b=int(raw_input('pleaseinputnumber2:'))

  print"the+oftheresultis:%sn

  the-oftheresultis:%sn

  the*oftheresultis:%sn

  the/oftheresultis:%s"%(a+b,a-b,a*b,a/b)

  因为int是整数,我不知道怎么进行小数的运算,求教!

1回答
2019-12-25 06:53
我要回答
请先登录
龙连文

  什么意思?你将a、b定义为float型不就可以了吗?

  fromat()比%格式化输出强悍,最好学会用format格式化:

  如保留2位小数:'{0:0.2}.format(1.2/7)===0.17

2019-12-25 06:54:27

最新问答

推荐文章

猜你喜欢

附近的人在看

推荐阅读

拓展阅读

  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  •