Python: Remove division decimal

前端 未结 7 2094
予麋鹿
予麋鹿 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)
    

提交回复
热议问题