Basic python arithmetic - division

后端 未结 6 794
眼角桃花
眼角桃花 2021-01-05 14:40

I have two variables : count, which is a number of my filtered objects, and constant value per_page. I want to divide count by per_page and get integer value but I no matter

6条回答
  •  失恋的感觉
    2021-01-05 15:40

    its because how you have it set up is performing the operation and then converting it to a float try

    count = friends.count()
    print count
    
    per_page = float(2)
    print per_page
    
    pages = math.ceil(count/per_pages)
    
    print pages
    pages = count/per_pages
    

    By converting either count or per_page to a float all of its future operations should be able to do divisions and end up with non whole numbers

提交回复
热议问题