Python: Remove division decimal

前端 未结 7 2041
予麋鹿
予麋鹿 2020-12-29 21:05

I have made a program that divides numbers and then returns the number, But the thing is that when it returns the number it has a decimal like this:

2.0


        
相关标签:
7条回答
  • 2020-12-29 21:34

    You could probably do like below

    # p and q are the numbers to be divided
    if p//q==p/q:
        print(p//q)
    else:
        print(p/q)
    
    0 讨论(0)
提交回复
热议问题